python-3.x

Converting Python 2.x function definition into Python 3.x

I have a function definition in a Python 2.x script which takes a tuple as one of its arguments, but 2to3 has no answers nor any of my searching on how to represent the same in Python 3.x eg. def blah(self, (string1, string2)): Any help greatly appreciated ...

Using Python to replace "\r\r\n" with "\r\n" in a binary file

I'm very new to Python and just crawling my way through it to accomplish a task and would appreciate some help (Python 3.1). I have a CSV file written with DictWriter with a dialect of "excel". After the file is created, I'm notice extra lines in the file, and upon closer inspection it's because I have "\r\r\n" at the end of each line ...

Regex + Python to remove specific trailing and ending characters from value in tab delimited file

It's been years (and years) since I've done any regex, so turning to experts on here since it's likely a trivial exercise :) I have a tab delimited file and on each line I have a certain fields that have values such as: foo bar b"foo's bar" b'bar foo' b'carbar' (A complete line in the file might be something like: 123\t b'bar foo'...

Python 3.1.1 'else if' Syntax

I'm a new Python programmer who is making the leap from 2.6.4 to 3.1.1. Everything has gone fine until I tried to use the 'else if' statement. The interpreter gives me a syntax error after the 'if' in 'else if' for a reason I can't seem to figure out. def function(a): if a == '1': print ('1a') else if a == '2' pr...

How to organize Python modules for PyPI to support 2.x and 3.x

I have a Python module that I would like to upload to PyPI. So far, it is working for Python 2.x. It shouldn't be too hard to write a version for 3.x now. But, after following guidelines for making modules in these places: Distributing Python Modules The Hitchhiker’s Guide to Packaging it's not clear to me how to support multiple so...

Schedule a repeating event in Python 3

I'm trying to schedule a repeating event to run every minute in Python 3. I've seen class sched.scheduler but I'm wondering if there's another way to do it. I've heard mentions I could use multiple threads for this, which I wouldn't mind doing. I'm basically requesting some JSON and then parsing it; its value changes over time. To use...

I have a list of names, some of them are fake, I need to use NLP and Python 3.1 to keep the real names and throw out the fake names.

I have no clue of where to start on this. I've never done any NLP and only programmed in Python 3.1, which I have to use. I'm looking at the site http://www.linkedin.com and I have to gather all of the public profiles and some of them have very fake names, like 'aaaaaa k dudujjek' and I've been told I can use NLP to find the real names, ...

GUI options with python 3.x

Hello all: I was wondering what options are available for Python 3.x? I know Tkinter is available as well as qt, but what about the other libraries? Any word on when some of them may be ported over to 3.x? ...

Are PyArg_ParseTuple() "s" format specifiers useful in Python 3.x C API?

I'm trying to write a Python C extension that processes byte strings, and I have something basically working for Python 2.x and Python 3.x. For the Python 2.x code, near the start of my function, I currently have a line: if (!PyArg_ParseTuple(args, "s#:in_bytes", &src_ptr, &src_len)) ... I notice that the s# format specifier ...

python: variable not getting defined after several conditionals

For some reason this program is saying that 'switch' is not defined. What is going on? #PYTHON 3.1.1 class mysrt: def __init__(self): self.DATA = open('ORDER.txt', 'r') self.collect = 0 cache1 = str(self.DATA.readlines()) cache2 = [] for i in range(len(cache1)): ...

What is the new way of checking "callable" methods in python 3.x?

Hi, I was studying introspection in Python, and as I was getting through basic examples, I found out that the callable built-in function is no longer available in Python 3.1. How can I check if a method is callable now? Thank you ...

Python - Check if numbers in list are factors of a number

Hey, I have a list of numbers (integers) (say, from 1 to 10). They're not necessarily consecutive, but they are in ascending order. I've prompted the user multiple times to enter a choice of the available numbers. When that number is entered, it is removed from the list along with any of its factors that may be there. I've prevent...

Python 2 dict_items.sort() in Python 3

I'm porting some code from Python 2 to 3. This is valid code in Python 2 syntax: def print_sorted_dictionary(dictionary): items=dictionary.items() items.sort() In Python 3, the dict_items have no method 'sort' - how can I make a workaround for this in Python 3? ...

Distribute pre-compiled python extension module with distutils

Quick one today: I'm learning the in's and out's of Pythons distutils library, and I would like to include a python extension module (.pyd) with my package. I know of course that the recommended way is to have distutils compile the extension at the time the package is created, but this is a fairly complex extension spanning many source f...

Deleting object in function

Let's say I have created two objects from class foo and now want to combine the two. How, if at all possible, can I accomplish that within a function like this: def combine(first, second): first.value += second.value del second #this doesn't work, though first.value *does* get changed instead of doing something like def combi...

Beginner python - stuck in a loop

I have two begininer programs, both using the 'while' function, one works correctly, and the other gets me stuck in a loop. The first program is this; num=54 bob = True print('The guess a number Game!') while bob == True: guess = int(input('What is your guess? ')) if guess==num: print('wow! You\'re awesome!') ...

How do I copy only the values and not the references from a Python list?

Specifically, I want to create a backup of a list, then make some changes to that list, append all the changes to a third list, but then reset the first list with the backup before making further changes, etc, until I'm finished making changes and want to copy back all the content in the third list to the first one. Unfortunately, it see...

Python 3 relative path conversion issue

Hi All I am currently working with converting Pycrypto over to Python 3.X Whilst I seem to have the cryptography side working the same cannot be said for the tests provided with the module :( I have used the tests under Python 2.64 and all works fine. I then ran '2to3' over the tests to generate new files in 3.X format. There are seve...

how to copy a dictionary in python 3.1 and edit ONLY the copy

can someone please explain this to me??? this doesn't make any sense to me.... I copy a dictionary into another and edit the second and both are changed???? ActivePython 3.1.0.1 (ActiveState Software Inc.) based on Python 3.1 (r31:73572, Jun 28 2009, 19:55:39) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or...

Python script not working when run from browser directly

I'm trying to run this script: import re, os def build_pool(cwd): global xtn_pool, file_pool xtn, xtn_pool = re.compile('\\.[0-9a-zA-Z]{1,4}$'), [] file_pool = [files for files in os.listdir(cwd) if os.path.isfile(files) and xtn.search(files)] # Lists all the file extension in the folder for file in file_pool: if not xtn_pool...