Re: Trouble using pinckle

2008-07-02 Thread Cédric Lucantis
arting > with the one in the stdlib. You may want to find out if any of these > packages fits your needs before reinventing the wheel ? Right, ConfigParser should do the trick for simpler things. -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: Trouble using pinckle

2008-07-02 Thread Cédric Lucantis
this object: class Prefs (object) : def __init__ (self) : self.values = { 'test': 1, ... } def save (self, f) : pickle.dump(self.values, f) def load (self, f) : self.values = pickle.load(f) -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: simple UnZip

2008-07-02 Thread Cédric Lucantis
relative file names, so you can just put them anywhere you want with: zlFile = open(os.path.join(DESTDIR, zItem), 'wb') or change the current directory, but the first way should be preferred. > print "Finished" > &&& > > This works, but I want to be able to specify a different output > location. > -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: How to modify the data in a binary file?

2008-07-02 Thread Cédric Lucantis
g your string in chars and getting the bytes values with ord (described here: http://docs.python.org/lib/built-in-funcs.html) : byte0 = ord(s[0]) byte1 = ord(s[1]) si = (byte0 << 8) | byte1 # or maybe the inverse ? or use the struct module: http://docs.python.org/lib/module-struct.html -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: beginner's questions - manipulating text files

2008-07-02 Thread Cédric Lucantis
> how to read that line number from a text file? etc.)| if you read the file with readlines(), just lines[lineno] you'll find more infos in the following sections: http://docs.python.org/lib/bltin-file-objects.html http://docs.python.org/lib/string-methods.html http://docs.python.org/lib/module-random.html -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: Attribute reference design

2008-07-02 Thread Cédric Lucantis
ttribute, finds it in the class members, and then creates an instance member with the result. Things would be different with a mutable type implementing the += operator. I discovered this in a middle of a project and it was hard to track all these assignments in my code to correct them, so I'd suggest to always access class members through the class instead of the instance, unless you have no choice or know exactly what you are doing. -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: regex help

2008-06-30 Thread Cédric Lucantis
number that > does'nt start with: > > > > 281 > > 713 > > 832 > > > > or > > > > 1281 > > 1713 > > 1832 > > > > > > is long distance any, help would be appreciated. sounds like str.startswith() is enough for yo

Re: List Performance

2008-06-30 Thread Cédric Lucantis
uot;Amortized" part of "Amortized Worst Case". Individual actions may take surprisingly long, depending on the history of the container. Also note that 5 items is a lot for a human being, not for a modern computer. -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: Function to import module to namespace

2008-06-29 Thread Cédric Lucantis
You can dynamically add objects to a module: >>> import os >>> os.foo = 'bar' >>> os.foo 'bar' >>> setattr(os, 'foo2', 'bar2') >>> os.foo2 'bar2' and for the loading part you can use the __import__ builti

Re: 2D online multiplayer framework?

2008-06-28 Thread Cédric Lucantis
tp://alleg.sourceforge.net/ ) or SDL, another good one with the same purpose: http://www.libsdl.org/ http://www.pygame.org/news.html both are (imho) very good and easy to learn, but they are C libraries so some knowledge of this language might help you to understand them. -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: Use of the "is" statement

2008-06-27 Thread Cédric Lucantis
sing is in the wrong context, what is the right > one? What problems did you have exactly ? -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: ConfigParser: Can I read(ConfigParser.get()) a configuration file and use it to call a funciton?

2008-06-26 Thread Cédric Lucantis
you can restrict the set of functions the user can give, excluding those which are not supposed to be called this way. -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: ask for a RE pattern to match TABLE in html

2008-06-26 Thread Cédric Lucantis
le(r'.*') ^ this is to avoid matching a tag name starting with table (like ) -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: Making code more efficient and effective

2008-06-26 Thread Cédric Lucantis
.sub(r'\4', line) print "'%s' -> '%s' '%s' '%s' '%s'" % (line, func_vis, func_type, func_name, func_args) It might be hard to read but will avoid a lot of obscure parsing code. I can't tell if it makes the

Re: extend getattr()

2008-06-26 Thread Cédric Lucantis
in dotted_attr.split('.') : obj = getattr(obj, attr) return obj a = A() print 'a.b.c = %s' % get_dotted_attr(a, 'b.c') -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: reading from list with paths

2008-06-25 Thread Cédric Lucantis
f = open(filename) print f.read() f.close() f_list.close() If you get an error, please post the full error message with the backtrace. -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: newb question on strings

2008-06-25 Thread Cédric Lucantis
re But imho escaping the quote in the first part would be more readable than using triple quotes: >>> name = "Frank's Laundry" >>> re.sub(r"([\"'])", r"\\\1", name) "Frank\\'s Laundry" You'll find a list of all the standard modules in the python docs, including this one: http://docs.python.org/modindex.html http://docs.python.org/lib/module-re.html -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: sending executable data over network..

2008-06-24 Thread Cédric Lucantis
ll have to run the same python version) so carefully read the docs first. I'd choose the first solution, eventually using the pickle module to avoid encoding problems. -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: Difference between two dates

2008-06-24 Thread Cédric Lucantis
tm2.tm_mon - 1) then (m1 - m2) gives the difference in months (see the time modules docs for more infos) -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: Find class attributes creation order

2008-06-23 Thread Cédric Lucantis
is your choice. You can use named params or a vararg list (which will preserve params order). But in your example you're only using class attributes, so __new__ is not involved and they are just created once for all in the order you write them: a, b, c. -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: Distutils and unit test files

2008-06-23 Thread Cédric Lucantis
> On Mon, Jun 23, 2008 at 9:59 AM, Cédric Lucantis <[EMAIL PROTECTED]> wrote: > > Yes a checksuite should be kept separate from the 'real' code. You can > > run it locally by setting the PYTHONPATH environment variable : > > > > PYTHONPATH=/path/to/your/

Re: Distutils and unit test files

2008-06-23 Thread Cédric Lucantis
s a checksuite should be kept separate from the 'real' code. You can run it locally by setting the PYTHONPATH environment variable : PYTHONPATH=/path/to/your/modules python checksuite.py -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: Trying to Learn Packages

2008-06-22 Thread Cédric Lucantis
enerate some code defining this value as a global variable, to make it accessible to the rest of your own code. Ideally, your app would also provide a command line option or an environment variable to override this hard-coded setting at runtime. But maybe the distutils tools have some features fo

Re: Way to unblock sys.stdin.readline() call

2008-06-21 Thread Cédric Lucantis
... > Do you mean setting stdin in non-blocking mode ? On unix you can do it with the fcntl module (you'll find more infos in the libc docs) : fcntl.fcntl(sys.stdin, fcntl.F_SETFL, os.O_NONBLOCK) and catch IOErrors with errno = EAGAIN. But I don't know how to do it in a portable way, sug

Re: Getting Python to run Python Scripts in cygwin

2008-06-19 Thread Cédric Lucantis
ne style you've chosen at cygwin installation time. (See http://en.wikipedia.org/wiki/Newline#Common_problems) -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: Installing Python 3.0 no probs running 2.5 at the same time?

2008-06-19 Thread Cédric Lucantis
nt major/minor version numbers (so 2.4 + 2.5 is OK, but _not_ 2.4.2 + 2.4.4). Everything go in different directories, and a version specific executable is also installed (python2.5, python3.0...). The main one (python) is just a link to one of them. -- Cédric Lucantis -- http://mail.python.org/ma

Re: Convert string to array of floats

2008-06-19 Thread Cédric Lucantis
.846290\n' > to an array of floats. > string = '0.906366 2.276152 0.01336980.773141' array = [float(s) for s in string.split()] -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple Python class questions

2008-06-19 Thread Cédric Lucantis
Le Thursday 19 June 2008 15:13:39 John Dann, vous avez écrit : > Many thanks for the speedy replies. > > On Thu, 19 Jun 2008 14:14:02 +0200, Cédric Lucantis <[EMAIL PROTECTED]> > > wrote: > >Le Thursday 19 June 2008 13:54:03 John Dann, vous avez écrit : > >&g

Re: Simple Python class questions

2008-06-19 Thread Cédric Lucantis
printing the method object itself without calling it : print serlink.openPort() -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: py2exe & application add-ons

2008-06-19 Thread Cédric Lucantis
lly know py2exe but I bet it can handle it without problem. -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple wxPython SetLabel question

2008-06-19 Thread Cédric Lucantis
; 'panel' is local to your __init__ function, so it's not available elsewhere. You should store it as an instance attribute instead : # in __init__: self.panel = wx.Panel(self) # in OnBrowse self.panel.database.SetLabel(patrh) note that unlike some other languages, panel and self.panel are two distinct variables, so you should replace _all_ references to panel by self.panel. -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: Function argument conformity check

2008-06-18 Thread Cédric Lucantis
the function accepts varargs like *args, **kwargs, but I don't know where these are defined. Note that I never found any doc about that and merely guessed it by playing with func objects, so consider all this possibly wrong or subject to change. -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: How to split a string containing nested commas-separated substrings

2008-06-18 Thread Cédric Lucantis
else : ret[-1] += car return ret # test for s in ('foo, bar, baz', 'foo, "bar, baz", blurf', 'foo, bar(baz, blurf), mumble') : print "'%s' => '%s'" % (s, mysplit(s)) # result 'foo, bar, baz' => '['foo', 'bar', 'baz']' 'foo, "bar, baz", blurf' => '['foo', 'bar, baz', 'blurf']' 'foo, bar(baz, blurf), mumble' => '['foo', 'bar(baz, blurf)', 'mumble']' -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: 'string'.strip(chars)-like function that removes from the middle?

2008-06-16 Thread Cédric Lucantis
.com'.strip('cmowz.') > 'example' > .??? --> --- 'www.example.com'.strip('cmowz.') > 'exaple' > -- I don't see any string method to do that, but you can use a regexp : >>> re.sub('[cmowz.]', '', 'www.example.com') 'exaple' -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: randrange loops

2008-06-15 Thread Cédric Lucantis
say something is wrong with your script but we'll need more infos to help. Can you post the whole function ? -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: problem with Py_BuildValue

2008-06-15 Thread Cédric Lucantis
sting) { if (op->ob_refcnt <= 0) /* XXX(twouters) cast refcount to long until %zd is universally available */ fprintf(fp, "", (long)op->ob_refcnt, op); } } I don't really understand its pur

Re: problem with Py_BuildValue

2008-06-15 Thread Cédric Lucantis
ent to use the float constructor directly: dummy = PyFloat_FromDouble(internal_list([i])) PS: always use Py_CLEAR(dummy) instead of Py_DECREF(dummy); dummy=NULL; (though it doesn't really matter in this simple case - see http://docs.python.org/api/countingRefs.html) -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Re: NoneType Error

2008-06-15 Thread Cédric Lucantis
or with the 'types' module, but it won't work as the except handler only accepts Exception classes. It sounds like you're confusing with some other error, what is the exact message of your 'NoneType error' ? The exception type you want to catch should be at the beginning

Re: Python Socket programming

2008-06-13 Thread Cédric Lucantis
endly manual :) http://docs.python.org/lib/module-socket.html and if you want to know more about socket themselves, the gnu libc info page is a good starting point as the python module is basically an interface to it: http://www.gnu.org/software/libc/manual/html_node/Sockets.html#Sockets

Re: TypeError with date class

2008-06-13 Thread Cédric Lucantis
date.__new__(cls, y, m, d) return self The general rule is to do your initialization in __new__ for immutable types and in __init__ for mutable ones. See the chapter 3 of the reference manual (data model) for more infos. -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list

Problem with Tkinter.PhotoImage

2008-01-10 Thread Cédric Lucantis
on-mode python-newt python-selinux python-semanage python-support python-tk python2.4 python2.4-doc python2.4-minimal thanks, -- Cédric Lucantis -- http://mail.python.org/mailman/listinfo/python-list