python-3.x

Looking for help, just started with Python today. (3.0)

I am just trying to get into python, but I've found it very difficult to find any resource that is Python 3. All I've got so far is diveintopython3.org, and its limited. Anyways, I was just trying to get a feel for the language by doing some very basic stuff, but I can't figure out why this little program won't do what I intend, which is...

File I/O in the Python 3 C API

The C API in Python 3.0 has changed (deprecated) many of the functions for File Objects. Before, in 2.X, you could use PyObject* PyFile_FromString(char *filename, char *mode) to create a Python file object, e.g: PyObject *myFile = PyFile_FromString("test.txt", "r"); ...but such function no longer exists in Python 3.0. What would b...

Problem with my hangman game

I'm trying to learn python and I'm attempting a hangman game. But when I try and compare the user's guess to the word, it doesn't work. What am I missing? import sys import codecs import random if __name__ == '__main__': try: wordlist = codecs.open("words.txt", "r") except Exception as ex: print (ex) pri...

Looking for ways to improve my hangman code

Just getting into python, and so I decided to make a hangman game. Works good, but I was wondering if there was any kind of optimizations I could make or ways to clean up the code. Also, if anyone could recommend a project that I could do next that'd be cool. import sys import codecs import random def printInterface(lst, attempts): ...

The wrong python interpreter is called

I updated my python interpreter, but I think the old one is still called. When I check for the version I get: $ python -V Python 3.0.1 But I believe the old interpreter is still being called. When I run the command: python myProg.py The script runs properly. But when I invoke it with the command ./myProg.py I get the error messa...

I can't find the logic error in this bubble sort code

I'm attempting to do a simple bubble sort code to get familiar with list/string manip & method use, but for some reason, when I attempt to iterate through each value in the list to remove white space and values that are non ints, it skips some. I haven't even gotten to the bubble sorting part.. #test data: 45,5j, f,e,s , , , 45,q, ...

How to write binary data in stdout in python 3?

In python 2.x I could do this: import sys, array a = array.array('B', range(100)) a.tofile(sys.stdout) Now however, I get a TypeError: can't write bytes to text stream. Is there some secret encoding that I should use? ...

Having trouble with str.find()

I'm trying to use the str.find() and it keeps raising an error, what am I doing wrong? import codecs def countLOC(inFile): """ Receives a file and then returns the amount of actual lines of code by not counting commented or blank lines """ LOC = 0 for line in inFile: if...

Why is the compiler package discontinued in Python 3?

I was just pleasantly surprised to came across the documentation of Python's compiler package, but noticed that it's gone in Python 3.0, without any clear replacement or explanation. I can't seem to find any discussion on python-dev about how this decision was made - does anyone have any insight inot this decision? ...

Is it possible to install python 3 and 2.6 on same PC?

How would I do this? The reason being I wanted to try some pygame out, but I have python 3 installed currently and have been learning with that. I'm also interested in trying out wxpython or something like that, but I haven't looked at their compatibilities yet. EDIT:: im on a windows vista 64-bit ...

When Should I Start Thinking About Moving to Python 3?

Possible Duplicate: Why won't you switch to Python 3.x? I see there are already a lot of duplicate questions asking whether or not new Python programmers should learn 2 or 3. I am not asking that question. I am already a Python 2 programmer. I started tinkering with it some years ago. I started using it almost exclusively for ...

str.startswith() not working as I intended

I'm trying to test for a /t or a space character and I can't understand why this bit of code won't work. What I am doing is reading in a file, counting the loc for the file, and then recording the names of each function present within the file along with their individual lines of code. The bit of code below is where I attempt to count th...

Formatting the output of a key from a dictionary

I have a dictionary which store a string as the key, and an integer as the value. In my output I would like to have the key displayed as a string without parenthesis or commas. How would I do this? for f_name,f_loc in dict_func.items(): print ('Function names:\n\n\t{0} -- {1} lines of code\n'.format(f_name, f_loc)) output: En...

str.startswith() not working as I intended

I can't see why this won't work. I am performing lstrip() on the string being passed to the function, and trying to see if it starts with """. For some reason, it gets caught in an infinite loop def find_comment(infile, line): line_t = line.lstrip() if not line_t.startswith('"""') and not line_t.startswith('#'): print (...

What are the used/unused features of Python 3?

I've recently did some web design as a hobby with a primary motivation to learn interesting things. It was certainly nice to learn Python, but I found out there has just been a Great Python Rewrite too late, so I had to learn both Python 3 and 2.6 essentially. I'm a newbie, so I'd like people to share what they think the strengths/weak...

Python3.0 - tokenize and untokenize

I am using something similar to the following simplified script to parse snippets of python from a larger file: import io import tokenize src = 'foo="bar"' src = bytes(src.encode()) src = io.BytesIO(src) src = list(tokenize.tokenize(src.readline)) for tok in src: print(tok) src = tokenize.untokenize(src) Although the code is not...

Easy: How to use Raw_input in 3.1

import sys print (sys.platform) print (2 ** 100) raw_input( ) I am using Python 3.1 and can't get the raw_input to "freeze" the dos pop-up. The book I'm reading is for 2.5 and I'm using 3.1 What should I do to fix this? Thanks. ...

Is storm Python 3 compatible?

I haven't found any information on that topic and its homepage doesn't mention it. ...

python3.0: imputils

Why was the imputil module removed from python3.0 and what should be used in its place? ...

PEP 302 Example: New Import Hooks

Where can I find an example implementation of the "New Import Hooks" described in PEP 302? I would like to implement a custom finder and loader in the most forward compatible way possible. In other words, the implementation should work in python 2.x and 3.x. ...