Re: Simple Python Sandbox

2010-08-14 Thread Stephen Hansen
ring it to a crawl. I haven't figured out a strategy for trying to address that yet, and ultimately, I may not find one. That's okay: perfection isn't my goal, infinite loops are easy enough to do on accident that halting them is important. -- Stephen Hansen ... Also: Ixoka

Re: Simple Python Sandbox

2010-08-14 Thread Stephen Hansen
On 8/14/10 8:11 PM, geremy condra wrote: > cpulimit or a cgroups container can both be easy solutions here, > depending on your exact needs. Hmm! I wasn't aware of those, I'll check that out. Thanks. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python

Re: Simple Python Sandbox

2010-08-20 Thread Stephen Hansen
On 8/16/10 7:01 AM, Roland Koebler wrote: > On Sat, Aug 14, 2010 at 08:01:00PM -0700, Stephen Hansen wrote: >>> As you can see, black listing isn't the best approach here. >> >> But I have a two pronged strategy: the black list is only half of the >> equation.

Re: Simple Python Sandbox

2010-08-21 Thread Stephen Hansen
On 8/21/10 5:56 PM, Gregory Ewing wrote: > Stephen Hansen wrote: > >> Me, I'm going to go farther on my own installation and kill import >> entirely, and do a sort of require() which returns a special proxied >> version of an imported module > > Note that you

Re: Scope objects

2009-06-05 Thread Stephen Hansen
On Fri, Jun 5, 2009 at 6:56 PM, Robert Dailey wrote: > Is it possible to create an object in Python that will clean itself up > at function exit? I realize destruction of objects may not occur > immediately and can be garbage collected, but this functionality would > still be great to have. Consi

Re: preferring [] or () in list of error codes?

2009-06-08 Thread Stephen Hansen
On Mon, Jun 8, 2009 at 2:36 PM, wrote: > Is there any reason to prefer one or the other of these statements? > >if e.message.code in [25401,25402,25408]: >if e.message.code in (25401,25402,25408): > > I'm currently using [], but only coz I think it's prettier > than (). I like t

Re: Lexical scope: converting Perl to Python

2009-06-12 Thread Stephen Hansen
> > private_hash = dict( A=42, B=69 ) > def public_fn(param): >return private_hash[param] > print public_fn("A") # good: prints 42 > x = private_hash["A"]# works: oops, hash is in scope > > I'm not happy with that because I'd like to limit the scope of the > private_hash variable s

Re: Forwarding keyword arguments

2009-06-23 Thread Stephen Hansen
> Suppose I have 2 functions like so: > > def Function2( **extra ): > # do stuff > > def Function1( **extra ): > Function2( extra ) > > As you can see, I would like to forward the additional keyword > arguments in variable 'extra' to Function2 from Function1. How can I > do this? I'm using Pyth

Re: What are the limitations of cStringIO.StringIO() ?

2009-07-01 Thread Stephen Hansen
> > >1. Anyone knows whet's the limitation on cStringIO.StringIO() objects ? >2. Could you suggest a better way to create a string that contains the >concatenation of several big files ? > > This isn't a limit in cStringIO.StringIO, but a limit on the amount of memory a process is able

Re: delayed sys.exit?

2009-07-29 Thread Stephen Hansen
> > In the attached http://www.nabble.com/file/p24726902/test.py test.py > code, > it appears that additional statements execute after the call to > sys.exit(0). > I'll be grateful if anyone can shed light on why this is happening. Below > is a copy of some sample I/O. Note that in the last case

Re: boolean OR gotcha

2009-08-04 Thread Stephen Hansen
> > > # Here is something different: > >>> (0 or None) == (None or 0) > False What is the actual problem? You quoted the docs, it seems very clear. (0 or None) would return None. (None or 0) would return 0. None is not equal to 0, of course. --S -- http://mail.python.org/mailman/listinfo/pyt

Re: Problem with join in__str__() in class (newbie)

2009-08-09 Thread Stephen Hansen
output += '\nKnown topics: %s' % (', '.join(str(self.topics))) Your problem is here. self.topics is a list of topic instances: but you're calling str() on the list itself to turn the LIST itself into a string. Compare: >>> x = [1,2,3] >>> x [1, 2, 3] >>> str(x) '[1, 2, 3]' Now, after str(se

Re: Problem with join in__str__() in class (newbie)

2009-08-09 Thread Stephen Hansen
> > only the first topic is printed. If topics only contain a single topic I > get this error: > Traceback (most recent call last): > File "C:\Users\fencer\workspace\Find Expert\src\find_expert.py", line 57, > in >print experts[1] > File "C:\Users\fencer\workspace\Find Expert\src\find_expert

Re: Python "and" behavior

2009-08-13 Thread Stephen Hansen
> > Could you explain or link me to an explanation of this? Been using > Python for a while but not sure I understand what's happening below. > Thanks. > > >>> ss=1 and "f" > >>> ss > 'f' > >>> ss=0 and "f" > >>> ss > 0 > >>> The "and" and "or" operators in Python are actually not tru

Re: i Don't get why it makes trouble

2009-08-13 Thread Stephen Hansen
> > Currently I am working on just a prototype to show what is possible to > be done to get me some fundings for my future work. after that I will > get over to an SQL Alchemy. It's ORM will take over this business for > me. > > A lot of people a not aware of SQL injection. My friend from college >

Re: Python 'for' loop is memory inefficient

2009-08-14 Thread Stephen Hansen
> > It seems as though Python is actually expanding range(2,n) into a list of > numbers, even though this is incredibly wasteful of memory. There should be > a looping mechanism that generates the index variable values incrementally > as they are needed. This has nothing to do with Python's for l

Re: Splitting on '^' ?

2009-08-16 Thread Stephen Hansen
And .splitlines seems to be able to handle all "standard" end-of-line > markers without any special direction (which, ironically, strikes > me as a *little* Perlish, somehow): > > >>> "spam\015\012ham\015eggs\012".splitlines(True) > ['spam\r\n', 'ham\r', 'eggs\n'] > ... actually "working correctly

Re: Problem with winreg - The object is not a PyHKEY object

2009-08-21 Thread Stephen Hansen
On Fri, Aug 21, 2009 at 9:33 AM, Jamie wrote: > My goal is to remotely remove the registry keys for McAfee. I don't > know how winreg handles an exception if a key doesn't exist, but I > setup my script to skip the exception. But it doesn't seem to work > right.. I think the script should be self

Re: TypeError while checking for permissions with os.access() on windows xp

2009-08-22 Thread Stephen Hansen
> > > WTF?? > Why on IDLE it works, but when i run this script in cmd.exe, the > os.getenv('HOME') goes NoneType? > I'm to newbie yet to understand this :/ > HOME is simply not a standard environment variable that Windows provides. Any program can set/add environment variables as it deems fit; in

Re: IOError: [Errno 22] invalid mode ('wb') or filename: in windows xp while making tarfile

2009-08-24 Thread Stephen Hansen
> > The proper path is "C:\\Users\\Ryniek's > WinSe7en\\MyNewGGBackup(2009-08-23 14:59:02).tar.bz2" > and that string literal is "\U", without any pipes :) > > The truth is that script works on linux (ubuntu) but not on windows > (neither Win7 nor WinXP). > Maybe it's good idea to use raw string f

Re: Python for professsional Windows GUI apps?

2009-08-24 Thread Stephen Hansen
> >I was wondering if some people in this ng use Python and some GUI > toolkit (PyWin32, wxWidgets, QT, etc.) to build professional > applications, and if yes, what it's like, the pros and cons, etc. My company does. A few years ago we decided to re-write our entire aging product line in

Re: print() and unicode strings (python 3.1)

2009-08-24 Thread Stephen Hansen
> > > You should be setting the terminal encoding administratively, not > > programmatically. > > > > The terminal encoding has always been utf-8. It was not set > programmatically. > > It seems to me that python 3.1's string handling is broken. > Apparently, in python 3.1 I am unable to explicitl

Re: Need help with Python scoping rules

2009-08-25 Thread Stephen Hansen
> > > But http://docs.python.org/tutorial/classes.html says, in Section 9.3 "A > First Look at Classes": > > When a class definition is entered, a new namespace is created, > and used as the local scope — thus, all assignments to local variables > go into this new namespace. In particular, function

Re: Transforming a str to an operator

2009-08-27 Thread Stephen Hansen
> > num1 = raw_input('Enter the first number: ') > num2 = raw_input('Enter the second number: ') > op = raw_input('Select one of the following [+-*/]: ') > print 'The answer is: ', int(num1), eval(op), int(num2) > > > How do I convert the contents of "op"

Re: Transforming a str to an operator

2009-08-27 Thread Stephen Hansen
> > > I would use the following approach: > > Abviously the OP is a python baby noob and casting your irrational > fear (and many others irrational fears) of eval at him is akin to > tales of Chupacabras running a muck in the jungle sucking the blood > from live goats in the twilight hours. I use e

Re: An assessment of the Unicode standard

2009-08-29 Thread Stephen Hansen
> > Unicode (*puke*) seems nothing more than a brain fart of morons. And > sadly it was created by CS majors who i assumed used logic and > deductive reasoning but i must be wrong. Why should the larger world > keep supporting such antiquated languages and character sets through > Unicode? What pur

Re: An assessment of the Unicode standard

2009-08-30 Thread Stephen Hansen
> > So why the heck are we supporting such capitalistic implementations as > Unicode. Sure we must support a winders installer but Unicode, dump > it! We don't support a Python group in Chinese or French, so why this? > Makes no sense to me really. Let M$ deal with it. > Who, exactly, do you think

Re: Thread Pool

2009-08-30 Thread Stephen Hansen
On Sun, Aug 30, 2009 at 9:56 AM, Vitaly Babiy wrote: > Hey, > Any one know of a good thread pool library. I have tried a few but they > don't seem to clean up after them selfs well. > > Thanks, > Vitaly Babiy > > As obscene as it seems, I actually use twisted's :) I mean, it's obscene not becaus

Re: Thread Pool

2009-08-30 Thread Stephen Hansen
On Sun, Aug 30, 2009 at 1:06 PM, John Haggerty wrote: > twisted? I don't get it > Twisted. Big library / framework for network'd applications. Specifically, asynchronous network'd applications, really. --S -- http://mail.python.org/mailman/listinfo/python-list

Re: Python3: hex() on arbitrary classes

2009-09-01 Thread Stephen Hansen
On Tue, Sep 1, 2009 at 8:22 AM, Philipp Hagemeister wrote: > class X(object): >def __int__(self): return 42 >def __hex__(self): return '2b' #sic > > hex(X()) > > > What would you expect? Python2 returns '2b', but python 3(74624) throws > TypeError: 'X' object cannot be interpreted as an in

Re: Q on naming nested packages/modules

2009-09-01 Thread Stephen Hansen
> >> An implication of all this is that if now I wanted to create a new > >> module x.y.z.w, this means that the previously "leaf"-module x.y.z > >> would become "non-leaf". In other words, I'd have to: > >> > >> 1. create the new directory x/y/z > >> 2. *rename* the file x/y/z.py to x/y/z/__init_

Re: string find mystery

2009-09-02 Thread Stephen Hansen
> > The amazing thing is when file_str = 'C:\Qt\SimLCM\Default > \Data_Input_Material.txt', > the first if statement if fulfilled, that seemingly says that in this > file_str, python actually finds the word 'Geometry'. > I know this, because the line: 'I found geometry' is printed. However, > if i

Re: string find mystery

2009-09-02 Thread Stephen Hansen
On Wed, Sep 2, 2009 at 10:33 PM, Helvin Lui wrote: > Thanks! I just realised that too, but I used the condition:.find() > > 0 But I think your's is better. > Simple programming knowledge... > < > Ah, but != 0 vs > 0 isn't a question of better, but correctness: because if .find() returns 0,

Re: Q on explicitly calling file.close

2009-09-05 Thread Stephen Hansen
On Sat, Sep 5, 2009 at 6:51 PM, kj wrote: > In <02b2e6ca$0$17565$c3e8...@news.astraweb.com> Steven D'Aprano < > st...@remove-this-cybersource.com.au> writes: > > >(3) For quick and dirty scripts, or programs that only use one or two > >files, relying on the VM to close the file is sufficient (alt

Re: Q on explicitly calling file.close

2009-09-06 Thread Stephen Hansen
> > It's just too bad that 'with' doesn't support multiple separate "x as y" >> clauses. >> > > The developers already agreed with you ;-). > > "With more than one item, the context managers are processed as if multiple > with statements were nested: > > with A() as a, B() as b: >suite > is equ

Re: Q on explicitly calling file.close

2009-09-06 Thread Stephen Hansen
On Sun, Sep 6, 2009 at 4:31 PM, r wrote: > On Sep 6, 1:14 pm, "Jan Kaliszewski" wrote: > > 05-09-2009 r wrote: > > > i find the with statement (while quite useful in general > > > practice) is not a "cure all" for situations that need and exception > > > caught. > > > > In what sense? > > *ahem

Re: Question regarding handling of Unicode data in Devnagari

2009-09-12 Thread Stephen Hansen
> > As per the standard posted by the UNICODE for the Devnagari script > used for Hindi and some other languages of India, we have a standard > set, like from the range of 0900-097F. > Where, we have numbers for each character: > like 0904 for Devnagari letter short a, etc. > Now, if write a progra

Re: detmining name during an assignment

2009-09-18 Thread Stephen Hansen
On Fri, Sep 18, 2009 at 10:00 AM, Jamie Riotto wrote: > I have an app that uses Python scripting. When a user creates a new object: > > objName = newObject() > > I'd like the newObject be able to use objName as its internal name. > Almost this exact same question came up not so long ago, which is

Re: Deformed Form

2010-06-10 Thread Stephen Hansen (L/P)
t somewhere). The latter is -- a class? A function? No idea, as you haven't shown us. Nor shown any errors or any tracebacks or *anything* to indicate what is possibly going on, let alone what is going wrong when you, I presume, attempt to "call .. something .. from the calling script". (?

<    3   4   5   6   7   8