Re: what is it, that I don't understand about python and lazy evaluation?

2009-08-13 Thread Brian Allen Vanderburg II
Erik Bernoth wrote: Hi List, look at the following code: def evens(): # iterator returning even numbers i = 0 while True: yield i i += 2 # now get all the even numbers up to 15 L = [n for n in evens() if n 15] Isn't it strange, that this code runs (in a lazy

How to do relpath implementation on 2.5

2009-08-08 Thread Brian Allen Vanderburg II
I've coded my own 'relpath' implementation for 2.5 (shown below) and I want to make sure it follows as closely as it should to 2.6 and later. I've got a question regarding that. When attempting to convert to a relative path and it is not possible for some reason (different drive or UNC

Re: Copying objects and multiple inheritance

2009-06-03 Thread Brian Allen Vanderburg II
Gabriel Genellina wrote: En Tue, 02 Jun 2009 19:02:47 -0300, Brian Allen Vanderburg II brianvanderbu...@aim.com escribió: What is the best way to copy an object that has multiple inheritance with the copy module. Particularly, some of the instances in the hierarchy (...some of the classes

Copying objects and multiple inheritance

2009-06-02 Thread Brian Allen Vanderburg II
What is the best way to copy an object that has multiple inheritance with the copy module. Particularly, some of the instances in the hierarchy use the __copy__ method to create a copy (because even for shallow copies they need some information updated a little differently), so how can I

Re: Understanding descriptors

2009-02-05 Thread Brian Allen Vanderburg II
bruno.42.desthuilli...@websiteburo.invalid wrote: So the lookup chain is: 1/ lookup the class and bases for a binding descriptor 2/ then lookup the instance's __dict__ 3/ then lookup the class and bases for a non-binding descriptor or plain attribute 4/ then class __getattr__ Also and FWIW,

Re: Flattening lists

2009-02-05 Thread Brian Allen Vanderburg II
mrk...@gmail.com wrote: Hello everybody, Any better solution than this? def flatten(x): res = [] for el in x: if isinstance(el,list): res.extend(flatten(el)) else: res.append(el) return res a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]] print

Re: Flattening lists

2009-02-05 Thread Brian Allen Vanderburg II
mrk...@gmail.com wrote: Baolong zhen wrote: less list creation. At the cost of doing this at each 'flatten' call: if res is None: res = [] The number of situations of executing above code is the same as the number of list creations (once for each 'flatten' call, obviously). Is list

Re: Converting numbers to words

2009-02-05 Thread Brian Allen Vanderburg II
todp...@hotmail.com wrote: I've been trying to figure this out for over 2 hours and I'm really frustrated right now. I first made Python to ask user to input height in meters. If user puts certain value in meter, then it converts it to feet and inches as follows: Enter the height

Re: Why such different HTTP response results between 2.5 and 3.0

2009-02-01 Thread Brian Allen Vanderburg II
an0...@gmail.com wrote: Below are two semantically same snippets for querying the same partial HTTP response, for Python2.5 and Python 3.0 respectively. However, the 3.0 version returns a not-so-right result(msg) which is a bytes of length 239775, while the 2.5 version returns a good msg which

Understanding descriptors

2009-01-29 Thread Brian Allen Vanderburg II
I'm trying to better understand descriptors and I've got a few questions still after reading some sites. Here is what I 'think', but please let me know if any of this is wrong as I'm sure it probably is. First when accessing an attribute on a class or instance it must be found. For an

Re: new.instancemethod questions

2009-01-29 Thread Brian Allen Vanderburg II
schi...@gmail.com wrote: On Jan 29, 7:38 pm, Mel mwil...@the-wire.com wrote: schickb wrote: I'd like to add bound functions to instances, and found the instancemethod function in the new module. A few questions: 1. Why is instancemethod even needed? Its counter-intuitive (to me

Re: libsudo ?

2009-01-29 Thread Brian Allen Vanderburg II
linuxguy...@gmail.com wrote: Does anyone know where I would find libsudo ? http://sourceforge.net/projects/libsudo If you had the choice of using pexpect or libsudo, which would you use ? libsudo does all the work for you of executing sudo, checking for the expected responses and all.

Re: USB in python

2009-01-26 Thread Brian Allen Vanderburg II
astan.c...@al.com.au wrote: Tim Roberts wrote: Sorry, but you have NOT created a USB device, and I sincerely hope you do not try to plug it in to a real USB port. Sorry, by USB device, I meant a device that is powered/activated by a bunch of wires that I want to control using a computer

Re: understanding nested lists?

2009-01-24 Thread Brian Allen Vanderburg II
vinc...@vincentdavis.net wrote: I have a short peace of code that is not doing what I expect. when I assign a value to a list in a list alist[2][4]=z this seems replace all the 4 elements in all the sub lists. I assume it is supposed to but this is not what I expect. How would I assign a value

Re: Dynamic methods and lambda functions

2009-01-23 Thread Brian Allen Vanderburg II
unine...@gmail.com wrote: class Person: def __init__(self): for prop in props: setattr(self, __ + prop[0], prop[1]) setattr(Person, Get + prop[0], lambda self: getattr (self, __ + prop[0])) I've had a similar problem here and here is best how I can explain

Re: How do I get my python program to get the root password ?

2009-01-23 Thread Brian Allen Vanderburg II
gra...@visi.com wrote: On 2009-01-24, Linuxguy123 linuxguy...@gmail.com wrote: I want to make a python program that I can run as a normal user that changes the permission on some device files. It will need to ask me for the root password and then run chown as root in order to do this.

Re: USB in python

2009-01-22 Thread Brian Allen Vanderburg II
astan.c...@al.com.au wrote: Hi, Im trying to write a program for my USB device and I'm thinking of using python to do this. The USB device is of my own making and it is activated when one of the two data pins of the USB is given about 5V (or similar to whatever the power pin is getting). Now

Re: pep 8 constants

2009-01-22 Thread Brian Allen Vanderburg II
bock...@virgilio.it wrote: Constants would be a nice addition in python, sure enough. But I'm not sure that this can be done without a run-time check every time the constant is used, and python is already slow enough. Maybe a check that is disabled when running with optimizing flags ? But I'm

Idea to support public/private.

2009-01-22 Thread Brian Allen Vanderburg II
Okay so I don't really care about public/private but I was watching the lists (Does python follow its idea of readability or something like that) and I thought of a 'possible' way to add this support to the language. I have implemented a class which allows creating both a private as well as a

Re: Idea to support public/private.

2009-01-22 Thread Brian Allen Vanderburg II
There was a small error in setprivate/getprivate: import sys import inspect def get_private_codes(class_): codes = [] for i in class_.__dict__: value = class_.__dict__[i] if inspect.isfunction(value): codes.append(value.func_code) return codes def

Re: USB in python

2009-01-22 Thread Brian Allen Vanderburg II
astan.c...@al.com.au wrote: Hi, Thanks for all the responses but I forgot to mention that I have very little hardware understanding (at least in english) and the device itself it very simple and only needs about 5V power to be active. The problem here is that I want to control when the device

Re: Does Python really follow its philosophy of Readability counts?

2009-01-14 Thread Brian Allen Vanderburg II
rt8...@gmail.com wrote: Here is a piece of C code this same guy showed me saying Pythonic indention would make this hard to read -- Well lets see then! I swear, before god, this is the exact code he showed me. If you don't believe me i will post a link to the thread. // Warning ugly C code

Python threading

2009-01-13 Thread Brian Allen Vanderburg II
I'm doing some multi-threaded programming and before diving into the C/C++ code I though I'd do some in Python first. I decided to read through the threading module and I understand some of it, but I don't understand this, though I'm sure it is easy: The condition object has a method

Re: If programming languages were religions...

2008-12-19 Thread Brian Allen Vanderburg II
martin.lal...@gmail.com wrote: very interesting http://www.aegisub.net/2008/12/if-programming-languages-were-religions.html Python would be Humanism: It's simple, unrestrictive, and all you need to follow it is common sense. Many of the followers claim to feel relieved from all the burden

Re: Relative imports in Python 3.0

2008-12-17 Thread Brian Allen Vanderburg II
nicholas.c...@gmail.com wrote: Imagine a module that looks like ModuleDir __init__.py a.py b.py In python 2.x I used to have tests at the end of each of my modules, so that module b.py might look something like import a .. .. if __name__ == '__main__':

Re: Limit traceback from most recent call

2008-12-15 Thread Brian Allen Vanderburg II
yinon...@gmail.com wrote: On Dec 14, 8:07 pm, Brian Allen Vanderburg II brianvanderbu...@aim.com wrote: Hi, The interface of extract_tb is: traceback.extract_tb(tb, limit=None) try to play with the 'limit' argument Good luck, Yinon -- http://mail.python.org/mailman/listinfo/python-list

Limit traceback from most recent call

2008-12-14 Thread Brian Allen Vanderburg II
I've looked at traceback module but I can't find how to limit traceback from the most recent call if it is possible. I see that extract_tb has a limit parameter, but it limits from the start and not the end. Currently I've made my own traceback code to do this but wonder if python already

Re: Bidirectional Networking

2008-12-13 Thread Brian Allen Vanderburg II
man...@gmail.com wrote: On Dec 13, 11:13 pm, Bryan Olson fakeaddr...@nowhere.org wrote: Software firewalls will often simply refuse incoming connections. The basic protection of the garden-variety home router comes from network address translation (NAT), in which case TCP connections

Re: How to initialize a class variable once

2008-12-09 Thread Brian Allen Vanderburg II
[EMAIL PROTECTED] wrote: Unless you are calling reload() on the module, it will only ever get _loaded_ once. Each additional import will just yield the existing module. Perhaps if you post an example of the behavior that leads you to believe that the class variables are getting reinitialized I

Python idea/proposal to assist in single-archive python applications

2008-12-07 Thread Brian Allen Vanderburg II
Python Community The following is just an idea that I considered that may be helpful in creating an application in a single archive easier and with less code. Such an application would be similar to jar files for Java. First, the application and all data files should be able to run either

Re: Python idea/proposal to assist in single-archive python applications

2008-12-07 Thread Brian Allen Vanderburg II
[EMAIL PROTECTED] wrote: Why not use pkgutil.get_data()? Provided you remember to put your zip file on PYTHONPATH you can already run modules directly out of a zipfile (Python 2.5 and later).If your zipfile contains __main__.py then with Python 2.6 or later you can run it directly: just