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
»

I am quite new in Python, and am currently working on a code in which I want to store previous iterations of an 3-dimensional matrix, a version of which is created in each single step of a for-loop. The way I want to go about this is by concatenating... more
»

Why in the following program is an IndentationError being raised rather than SyntaxError?
>>> if True:
... print "just right!"
File "<stdin>", line 2
print "just right!"
^
IndentationError: Missing parentheses in call to... more
»

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
»

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
»

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
»

I would like to create a dictionary of values resulting from a split() sequence without whitespace.
If I had a list of strings that were formatted like so:
lines = ['Item1 = A Item2 = B Item3 = C',
'Item4 = D Item5 = E'... more
»

My data is absence records from a factory. Some days there are no absences so there is no data or date recorded for that day. However, and where this gets hairy with the other examples shown, is on any given day there can be several absences for va... more
»

I understand that __new__ is a static method and super() can be called from it create a new object, like so:
>>> class A:
... def __new__(cls):
... print('__new__ called')
... return super().__new__(cls)
...
>>>... more
»

I have a string like this
the gray fox
and I'd like to surround the word gray with the strings <b> and </b>. What is the most effective (and preferred) way to do this in Python?
(Context: I am building an application with a search fun... more
»

A recent question about splitting a binary file using null characters made me think of a similar text-oriented question.
Given the following file:
Parse me using spaces, please.
Using Perl 6, I can parse this file using space (or any chosen cha... more
»

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
»

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
»

I'm having an issue where I have a non required self many-to-many relationship that when saving a new object to an empty psql db gives me:
Edit: This is when I'm admin saving, there is no view that saves the model.
ValueError: "Video: Teste" nee... more
»

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
»

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
»

For real time plotting the COM port data in python, I need to make a fixed length array, if new value is received it keeps it at last index and when array is filled, upon next update, it dumps value at 1st index. In other words it keeps latest value ... more
»

I came across a different type of problem while scraping a webpage using python. When an image is clicked, new information concerning its' flavor comes up under the image. My goal is to parse all the flavors connected to each image. My script can par... more
»

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
»

I wrote a program in python that takes in a starting point and end point and then uses google maps API to create a gif of the route using google street view. Everything works perfectly I just can't find a way to get the bearing/heading of the car. Th... more
»

I want to do sprintf on python3 but with raw bytes objects, without having to do any manual conversions for the %s to work. So, take a bytes object as a 'template', plus any number of objects of any type and return a rendered bytes object. This is ho... more
»

From Python in a Nutshell:
Eschew global
Never use global if the function body just uses a global
variable (including mutating the object bound to that
variable, when the object is mutable).
Use a global statemen... more
»

I have made a program that stores login details that you have entered and allows you to login it with it into the main part of the menu. Everything was working fine when all the data types were strings, for example; modea = input("Etc") to allow the ... more
»

I was playing around with the OrderedDict type in Python 3.6 and was surprised by its behaviour. When I create a simple dict like this in IPython:
d = dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])
I get:
{'guido': 4127, 'jack': 4098, 's... more
»

I have a custom class,
class A:
def __init__(self, a, b):
self.a = a
self.b = b
The class is not iterable or indexable or anything like that. If at all possible, I would like to keep it that way. Is it possible to have somethin... more
»

I am developing django website and I want to use ldap authontation with my application. I am using Django 1.11 to authenticate with the django-python3-ldap.
I tested the connection to my ldap using ldapsearch and it was succeeded and I got the follow... more
»

I've read about Raymond Hettinger's new method of implementing compact dicts. This explains why dicts in Python 3.6 use less memory than dicts in Python 2.7-3.5. However there seems to be a difference between the memory used in Python 2.7 and 3.3-3.5... more
»

I have existing REST APIs, written using Django Rest Framework and now due to some client requirements I have to expose some of them as SOAP web services.
I want to know how to go about writing a wrapper in python so that I can expose some of my RE... more
»

Here is my personal/urls.py. I have been trying to solve this for quite a few days. I know it must be a really silly error but help would be appreciated.
from django.conf.urls import url, include
from . import views
urlpatterns = [
url(r'^$',view... more
»

I need to make a query after two selection of the parameters.
Something is rong is - Error during template rendering - valoare_detail.html and it is writing -
NoReverseMatch at /valoare/MICA/ Reverse for 'contract_list' with arguments '()' and key... more
»

I am new to Python. I am trying to extract one string ("concluded that our disclosure controls were effective as of") from a txt file ("infile.txt"). The file is relatively large, and I need to look for the above string in one particular section (bet... more
»

Recent Questions

I am hosting my website on PythonAnywhere.
I have two databases on the service: myusername$production and myusername$dev.
The production db backs itself up every night and loads the dev database with the most recent batch of live data. I am tryin...

There are multiple files in /opt/dir/ABC/ named allfile_123-abc allfile_123-def allfile_123-ghi allfile_123-xxx.
I need the files to be named new_name-abc.pgp new_name-def.pgp new_name-ghi.pgp new_name-xxx.pgp and then moved to /usr/tst/output
for ...

I'm trying to save some XML(UBL) documents into Marklogic 8 with date formatting incorrect like this:
<cbc:IssueDate>2017-06-32</cbc:IssueDate>
I'm using Java API to save it but can't save because of the next exception:
Server Mess...

In my project I want to manage 3 repositories:
PARENT
CHILD1
CHILD2
The reason I'm not using only one PARENT repository that contains CHILD1+CHILD2 is that CHILD1\2 can be used in other projects also.
In a specific stage I want to tag all 3 reposi...

Although there are several similar questions here (e.g., SVN - Reintegration Merge error: "must be ancestrally related") and on the Web, I wasn't able to figure out why svn mergeinfo <file> causes an error in all of my SVN repositories. In cont...