python-3.x

How to assure that filehandle.write() does not fail due to str/bytes conversions issues?

I need to detect if a filehandle is using binary mode or text mode - this is required in order to be able to encode/decode str/bytes. How can I do that? When using binary mode myfile.write(bytes) works, and when in text mode myfile.write(str) works. The idea is that I need to know this in order to be able to encode/decode the argument ...

Clyther-how to get started?

I don't get what Clyther is or how to use it. My stuff: ATI OpenCl SDK (just dl'd) clyther beta (just dl'd) windows 7 pro 64 bit active python 3.1.2 Xfxs Ati radeon 5850 video card I downloaded the ATI OpenCl SDK and the clyther beta from sourceforge. Then I tooke the sample 'reduce' function from the sourceforge documents ...

Passing class instantiations (layering)

Program design: Class A, which implements lower level data handling Classes B-E, which provide a higher level interface to A to perform various functions Class F, which is a UI object that interacts with B-E according to user input There can only be one instantiation of A at any given time, to avoid race conditions, data corrupti...

mod_wsgi authentication script

Hi. Can anybody help me? I've got a script like this: Can anybody write me easy script for user's authentication without frameworks, but with Apache/mod_wsgi and DBM file. I've seen http://code.google.com/p/modwsgi/wiki/AccessControlMechanisms, but i need an example. I've got Python3.1, mod_wsgi3.2, Apache2.2 Thanks. ...

iterating over dictionary items(), values(), keys() in p3k

If I understand correctly, in Python 2, iter(d.keys()) was the same as d.iterkeys(). But now, d.keys() is a view, which is in between the list and the iterator. What's the difference between a view and an iterator? In other words, in Python 3, what's the difference between for k in d.keys() f(k) and for k in iter(d.keys()) f...

How to convert raw html from the web into parsable xml in Python

I thought BeautifulSoup could do that, but it does not seem to do the trick. What method have you already used, and is long term reliable ? ...

Data Plotting Library for Python 3.x?

There are several threads for data plotting libs for python 2.x. What about python 3? Matplotlib's website says "not python 3." ...

Python 3.1: C3 method resolution order

A very simple case of diamond-type inheritance: class Root: def f(self): print('Root') class A(Root): pass class B(Root): def f(self): print('B') class AB(A, B): pass AB().f() According to Python 3.1.2 documentation: For most purposes, in the simplest cases, you can think of the search for attribute...

python: manipulating __dict__ of the class

(All in ActivePython 3.1.2) I tried to change the class (rather than instance) attributes. The __dict__ of the metaclass seemed like the perfect solution. But when I tried to modify, I got: TypeError: 'dict_proxy' object does not support item assignment Why, and what can I do about it? EDIT I'm adding attributes inside the cla...

How to install Python 3.1.2 on Mac OS X 10.6.4 ?

Hi there I have downloaded the mac installer here, http://www.python.org/download/releases/3.1.2/ , & installed it. But when I run terminal & type python it says: Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. ...

How i could access to the information inside the HTML

Hello i had a project what send information using the POST method to make a request in a server app write in Python, i want to know if after i make the request i can have full access to the elements in the page? ...

What is the use of FieldStorage in Python

I want to know whats the difference between FieldStorage in Python and wsgi_input? ...

Upload files without FieldStorage

How could i upload a file to a server without using FieldStorage in python? ...

Couldn't close file in functional way in python3.1?

I wrote a line of code using lambda to close a list of file objects in python2.6: map(lambda f: f.close(), files) It works, but doesn't in python3.1. Why? Here is my test code: import sys files = [sys.stdin, sys.stderr] for f in files: print(f.closed) # False in 2.6 & 3.1 map(lambda o : o.close(), files) for f in files: print(...

Sum numbers in an array

I'm a Python newbie. At this site, they show how to sum list of integers. What if instead of a list of raw ints, you had a list of class Number : def __init__( self, x = 0) : self.number = x def getNumber( self ) : return self.number What's the Python code to sum the self.number in an array in a few lines (...

REST web service in python 3?

Hi, I'm new to the python world and I'm currently in a new project using it. So since we we're there to learn, we chose to start with python 3. Now, we need to make a RESTful web service. After reading a few, I found out that the most used framework for web services is Django... and I also read on the Django website that it does not yet ...

How do I access outer functions variables inside a closure(python 2.6)?

From wikipedia I need to access outer functions variables in a similar manner as using the 'nonlocal' keyword from python 3.x. Is there some way to do that in python 2.6? (Not necessarily using the nonlocal keyword) ...

get console output

how can i receive the console output of any python file (errors, everything printed using the print() command)? example: main.py starts test.py and gets its output ...

Can stuck Python threads hinder other threads if there are no shared resources?

I am considering utilizing Python to call various dlls that will perform things like accessing the LAN (on Windows) or making HTTP requests. These dlls might be poorly written and get stuck. My first question is, whether isolating these dll calls in Python threads will guarantee that the main Python thread will not get stuck? My second q...

problem with python print function

I am trying to this function: def sleep(sec): for i in range(sec): print(".", end=" "); time.sleep(1); the problem is that it waits for the for loop to finish then it prints everything. If I use the normal print with \n in the end everything works as it should. But with the end=" " it does not. ...