python-3.x

Problem saving uploaded files in Python3

Hello, i control the problem of the data what is uploaded by the POST method, in the web if the file is a text theres no problem but the trouble comes when it's an enconded file as a Picture or other what the when the system insert the data into the file well it doesn 't encoded in the write way i will put all the code, from the area wha...

Python comparing two lists

Hello I wanna compare two lists like this a=[1,2] b=10,20] compare(a,b) will return True if each element in a is > corresponding element in b so compare( [1,2] > [3,4] ) is True compare( [1,20] > [3,4] ) is False hiow to do this the pythonic way Cheers ...

Python 3, easy_install, pip and pypi

What is the current status of easy_install, pip and the repository (pypi.python.org) with regards to Python 3.x? Are there versions of easy_install and/or pip that can install the right versions of packages from there? Else, are they expected soon? ...

Urllib raising invalid argument URLError in Python 3, urllib.request.urlopen

Hi. New to Python, but I'm trying to...retrieve data from a site: import urllib.request response = urllib.request.urlopen("http://www.python.org") This is the same code I've seen from the Python 3.1 docs. And a lot of sites. However, I get: Message File Name Line Position Traceback <module> G:\My...

How to encode upload file in Python3

Hello, i am trying to upload files to a web server using Python 3 but i can 't use a web framework because none uses python 3 so i' ve decide to make by my self just using the wsgiref lib all the process to handle with the upload information in the form, everything is ok when i upload the data coming from the fields but when i try to upl...

understanding zip function

All discussion is about python 3.1.2; see Python docs for the source of my question. I know what zip does; I just don't understand why it can be implemented like this: def zip(*iterables): # zip('ABCD', 'xy') --> Ax By iterables = map(iter, iterables) while iterables: yield tuple(map(next, iterables)) Let's say I ...

How save a binary file in Python3

I am trying to create a binary file in Python3 but i don 't know how to save it, the manual doesn 't say anything about that. i create a code but i don 't catch the mistake: s = open('/home/hidura/test.jpeg', 'wb') s.write(str.encode(formFields[5])) s.close() ...

Is there a way to emulate the __prepare__ special method of a Python 3-metaclass in Python 2.5?

In my project I have to stick to Python 2.5 (Google App Engine). Somewhere in the application (actually a framework), I have to keep track which variables are defined and in which order they are defined, in other words I would like to intercept whenever an assignment operator is processed. Using Python 3, I would define a metaclass M wi...

Image library for Python 3

What is python-3 using instead of PIL for manipulating Images? ...

pointer on ctypes to use opencv on Python 3.1

Hi, i try to use OpenCV on Python 3.1 through ctypes, but I do not know how represent pointers. Example, if I want to load an image and print the content of her first pixel, i will write in C++ : #include <opencv/cv.h> #include <opencv/highgui.h> using namespace std; int main() { IplImage *img; img = cvLoadImage("/home/foo/f...

Python filter / max combo - checking for empty iterator

(Using Python 3.1) I know this question has been asked many times for the general question of testing if iterator is empty; obviously, there's no neat solution to that (I guess for a reason - an iterator doesn't really know if it's empty until it's asked to return its next value). I have a specific example, however, and was hoping I ca...

exhausted iterators - what to do about them?

(In Python 3.1) (Somewhat related to another question I asked, but this question is about iterators being exhausted.) # trying to see the ratio of the max and min element in a container c filtered = filter(lambda x : x is not None and x != 0, c) ratio = max(filtered) / min(filtered) It took me half hour to realize what the problem is ...

Does anyone has Python 3 Cheat Sheet

Does anyone has python 3 cheat sheet. You know quick reference kind of thing which has everything on one page. Thank you in advance ...

Python 3 Urlopen vs Urlretreive

Hi, I am working on a script to download and process historical stock prices. When I used urllib.request.urlopen I got a strange prefix of text in every file (b'\xef\xbb\xbf) that was not present when I used urllib.request.urlretrieve, nor present when I typed the url into a browser (Firefox). So I have an answer but I don't know why i...

AttributeError: 'module' object has no attribute 'urlopen'

I'm trying to use Python to download the HTML source code of a website but I'm receiving this error. Traceback (most recent call last): File "C:\Users\Sergio.Tapia\Documents\NetBeansProjects\DICParser\src\WebDownload.py", line 3, in file = urllib.urlopen("http://www.python.org") AttributeError: 'module' object has no ...

Is Paramiko going to be ported over to Python 3.x?

Seems to be that PyCrypt is required to be ported, in order to make that happen. Is it hard to do yourself? ...

How to delete record from table?

Hi, I have a problem with deleting a record from sqlite3 database: conn = sqlite3.connect('databaza.db') c = conn.cursor() data3 = str(input('Please enter name: ')) mydata = c.execute('DELETE FROM Zoznam WHERE Name=?', (data3,)) conn.commit() c.close All is good, but delete doesn't work! Have anybody some idea? ...

Rename dictionary keys according to another dictionary

(In Python 3) I have dictionary old. I need to change some of its keys; the keys that need to be changed and the corresponding new keys are stored in a dictionary change. What's a good way to do it? Note that there may be an overlap between old.keys() and change.values(), which requires that I'm careful applying the change. The followi...

GUI-embeddable Python drawing widget with anti-aliasing

I am writing a small diagram drawing application (similar to Graphviz in spirit), and need a GUI library that would allow me to embed a canvas capable of drawing anti-aliased lines and text. I want to have a text editor in one half of the window to edit the diagram code and a (perhaps live) preview pane in the other. Right now I have th...

non-destructive version of pop() for a dictionary

Is there any idiom for getting an arbitrary key, value pair from a dictionary without removing them? (P3K) EDIT: Sorry for the confusing wording. I used the word arbitrary in the sense that I don't care about what I'm getting. It's different from random, where I do care about what I'm getting (i.e., I need probabilities of each item ...