How to check if a string is an integer

So I've been trying to make a calculator that solves for x, but I need to check whether a string is an integer or not. I try to put float("string") to check, but if it is not a floating point number, it displays an error: [ValueError: invalid lit...
more »

2017-08-10 23:08 (1) Answers

How to force dicts to be unordered (for testing)?

I've just spent half a day tracing down a bug to a dict that I forgot to sort when iterating over it. Even though that part of code is tested, the tests did not pick it up because that dict had a repeatable ordering during the test. Only when I shuff...
more »

2017-08-08 17:08 (1) Answers

Flatten nested try/except clauses

I want to try a number of different approaches at the same task, catching exceptions each time an approach fails. I know the exception which will be raised if an attempt fails (and it can be different for each attempt). After the last attempt, I want...
more »

2017-08-08 13:08 (3) Answers

Unable to parse links from xml content

I've written a script in python in combination with xpath to scrape links from a site with xml content. As I've never worked with xml, so I can't figure out where I'm making mistakes. Thanks in advance to provide me with a workaround. Here is what I'...
more »

2017-08-07 22:08 (1) Answers

Saving list of strings to csv file?

I am collecting data on a usb device and am getting 2 sets of data as a variable which contains 200 data points as comma-separated strings. How can I save these variables as csv files on my computer then? Ideally, I think I would like to do this in a...
more »

2017-08-03 17:08 (1) Answers

Python KeyError During Save/Load

So I was working on a program, and it used to SAVE/LOAD fine, and I have all the right imports and such, but recently, I've been getting this error message when I try to load (and a similar one during save): Traceback (most recent call last): Fil...
more »

2017-08-03 05:08 (1) Answers

Importing module not working

I have a django (but i think it's nor revelant here) project where I try to add a script i did before. So I put it in a subdirectory of my project, and i have this structure (I know it's a little bit of a mess at the moment but it won't stay exactly ...
more »

2017-08-01 10:08 (2) Answers

Parsing name/value pairs from XML

I am trying to pull account details from XML files supplied by vendors. I have one vendor that supplied XML files like: <Accounts> <Account> <AccountNumber>1234567</AccountNumber> <Balance>$200.00</Balance...
more »

2017-07-31 23:07 (4) Answers

How to expand a tuple in a yield?

I am trying to expand a tuple in a yield statement but I'm getting a SyntaxError. Is this even possible, or is the * operator only for function calls? Here is an example below: class Inner(object): def __init__(self): self._vals = {'a'...
more »

2017-07-29 20:07 (2) Answers

Python static method is not always callable

While parsing attributes using __dict__, my @staticmethod is not callable. Python 2.7.5 (default, Aug 29 2016, 10:12:21) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >&g...
more »

2017-07-28 16:07 (2) Answers