Re: slice iterator?

2009-05-09 Thread ryles
On May 8, 11:17 pm, Ross wrote: > I have a really long list that I would like segmented into smaller > lists. Let's say I had a list a = [1,2,3,4,5,6,7,8,9,10,11,12] and I > wanted to split it into groups of 2 or groups of 3 or 4, etc. Is there > a way to do this without explicitly defining new li

Re: unpickling a stream

2009-05-27 Thread ryles
On May 26, 3:25 pm, mso...@linuxmail.org wrote: > Hello, > > I want to send a stream of pickled objects over a socket.  Is there a > standard way of ensuring that only complete objects are unpickled on > the receiving side. > > client pseudo code: >   loop forever: >     receive some bytes on the s

Re: question about the GC implementation

2009-10-03 Thread ryles
On Oct 2, 11:20 am, Francis Moreau wrote: > Hello, > > I'm looking at gcmodule.c and in move_unreachable() function, the code > assumes that if an object has its gc.gc_refs stuff to 0 then it *may* > be unreachable. > > How can an object tagged as unreachable could suddenly become > reachable late

Re: weak reference to bound method

2009-10-04 Thread ryles
On Oct 2, 4:54 am, Ole Streicher wrote: > Hi group, > > I am trying to use a weak reference to a bound method: > > class MyClass(object): >     def myfunc(self): >         pass > > o = MyClass() > print o.myfunc > >   > > > import weakref > r = weakref.ref(o.myfunc) > print r() > >   Non

Re: Need feedback on subprocess-using function

2009-10-05 Thread ryles
On Oct 4, 9:46 pm, Nobody wrote: > On Sat, 03 Oct 2009 13:21:00 +, gb345 wrote: > > I'm relatively new to Python, and I'm trying to get the hang of > > using Python's subprocess module.  As an exercise, I wrote the Tac > > class below, which can prints output to a file "in reverse order", > >

Re: Python shared lib

2009-10-05 Thread ryles
On Oct 4, 11:04 am, a...@pythoncraft.com (Aahz) wrote: > I've got a dim memory that there's a reason for this -- you might try > searching the python-dev archives and/or bugs.python.org. Found mention of it in this discussion: http://bugs.python.org/issue771998 "I disagree that --enable-shared s

Re: How to find number of line that is currently executing?

2009-10-10 Thread ryles
On Oct 9, 11:46 pm, "Dr. Phillip M. Feldman" wrote: > I would like to put a statement on line N of my program that prints the line > number that is currently executing. inspect.currentframe().f_lineno http://docs.python.org/library/inspect.html -- http://mail.python.org/mailman/listinfo/python-

Re: Script to complete web form fields

2009-10-11 Thread ryles
On Oct 10, 9:39 pm, Feyo wrote: > How can I use Python to complete web form fields automatically? My > work web-based email time-out is like 15 seconds. Every time I need to > access my calendar, address book, or email, I have to type in my > username and password. I'm just tired of it. > > I foun

Re: code in a module is executed twice (cyclic import problems) ?

2009-10-11 Thread ryles
On Oct 10, 7:36 pm, Stef Mientki wrote: > hello, > > I always thought code in a module was only executed once, > but doesn't seem to be true. > > I'm using Python 2.5. > > And this is the example: > > == A.py == > My_List = [] > > == B.py == > from A import * > My_List.append ( 3 ) > print 'B', My

Re: strange behaviour when inheriting from tuple

2009-10-12 Thread ryles
On Oct 11, 3:04 am, metal wrote: > Environment: > > PythonWin 2.5.4 (r254:67916, Apr 27 2009, 15:41:14) [MSC v.1310 32 bit > (Intel)] on win32. > Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' > for further copyright information. > > Evil Code: > > class Foo: >         def

Re: restriction on sum: intentional bug?

2009-10-16 Thread ryles
On Oct 16, 11:39 am, Alan G Isaac wrote: > I expected this to be fixed in Python 3: > > >>> sum(['ab','cd'],'') > > Traceback (most recent call last): >    File "", line 1, in > TypeError: sum() can't sum strings [use ''.join(seq) instead] Then you probably haven't read through these discussions

Re: How about adding slice notation to iterators/generators?

2009-10-16 Thread ryles
On Oct 16, 5:28 pm, Eloff wrote: > By giving iterators a default, overridable, __getitem__ that is just > syntactic sugar for islice, they would share a slightly larger > interface subset with the builtin container types. In a duck-typed > language like python, that's almost always a good thing.

Re: Installation question 2.5.4

2009-10-17 Thread ryles
On Oct 17, 2:22 am, JimR wrote: > I completed the configure, the make and the make install.  However, the > last instruction in README is to perform > pkgmanager -a /usr/python > > As you may have guessed, Redhat does not have pkgmanager.  What can I do > to work-around this problem and get this l

Re: Installation question 2.5.4

2009-10-17 Thread ryles
On Sat, Oct 17, 2009 at 9:55 PM, JimR wrote: > Thanks. As it turned out, I needed /usr/local/python instead of /usr/local > as the prefix. After setting that, all worked as it should. -- http://mail.python.org/mailman/listinfo/python-list

Re: restriction on sum: intentional bug?

2009-10-19 Thread ryles
On Oct 16, 6:53 pm, ryles wrote: > Then you probably haven't read through these discussions: > > sum and > strings:http://mail.python.org/pipermail/python-list/2006-August/subject.html > summing a bunch of > numbers:http://mail.python.org/pipermail/python-dev/2003-Apri

Re: Anyone have python 3.1.1 installed on Solaris 10 ? (sparc or x86)

2009-10-20 Thread ryles
On Oct 19, 1:00 pm, Dave Crouse wrote: > Anyone have python 3.1.1 installed on Solaris 10 ? (sparc or x86) > > I've tried several times  on sparc, I keep getting: > > gcc -lintl -o python \ > Modules/python.o \ > libpython3.1.a -lsocket -lnsl -lintl -lrt -ldl -lm > Undefined first referenced > sym

Re: Copying a ZipExtFile

2009-10-28 Thread ryles
On Oct 23, 1:15 pm, "Moore, Mathew L" wrote: > Hello all, > > A newbie here.  I was wondering why the following fails on Python 2.6.2 > (r262:71605) on win32.  Am I doing something inappropriate? > > Interestingly, it works in 3.1, but would like to also get it working in 2.6. > > Thanks in advan

Re: Building Python on Solaris 10?

2009-10-28 Thread ryles
On Oct 28, 3:46 pm, Judy Booth wrote: > Can anyone point me towards some instructions for building Python on > Solaris 10? > We need this for some of our test scripts and so far we cannot get this > to build. > > We have tried both Python 2.6.4 and 3.1.1 and both fail with messages > like this: >

Re: Working threads progress

2009-10-28 Thread ryles
On Oct 28, 7:02 pm, mattia wrote: > Now, I would like to know the activity done (e.g. every two seconds) so I > create another thread that checks the queue size (using .qsize()). Have > you any suggestion to improve the code? It's not uncommon to pass each thread a second queue for output, which

Re: Copying a ZipExtFile

2009-10-28 Thread ryles
On Oct 28, 8:33 pm, ryles wrote: > As for why the bytesToRead calculation in ZipExtFile.read() results in > a long, I've not yet looked at it closely. Simple, actually: In ZipExtFile.__init__(): self.bytes_read = 0L In ZipExitFile.read(): bytesToRead = self.co

Re: Unhandled exception in thread

2009-06-12 Thread ryles
On Jun 11, 3:52 pm, Mads Michelsen wrote: > Here's the deal. The script in question is a screen scraping thing > which downloads and parses the html in the background using a separate > thread (the 'thread' module), while the main program serves up the > data to the user, allowing some modicum of

Re: generator expression works in shell, NameError in script

2009-06-18 Thread ryles
On Jun 18, 9:56 am, nn wrote: > On Jun 18, 8:38 am, guthrie wrote: > > > > > On Jun 17, 6:38 pm, Steven Samuel Cole > > wrote: > > > > Still don't really understand why my initial code didn't work, though... > > > Your code certainly looks reasonable, and looks to me like it "should" > > work. T

Re: generator expression works in shell, NameError in script

2009-06-19 Thread ryles
> Does the generator expression have its own little namespace or so ? Yes, generators create a new scope: http://docs.python.org/reference/expressions.html#grammar-token-generator_expression -- http://mail.python.org/mailman/listinfo/python-list

Re: Making code run in both source tree and installation path

2009-06-30 Thread ryles
On Jun 29, 12:20 pm, Javier Collado wrote: > Hello, > > I would like to be able to run the main script in a python project > from both the source tree and the path in which it's installed on > Ubuntu. The script, among other things, imports a package which in > turns makes use of some data files t

Re: Direct interaction with subprocess - the curse of blocking I/O

2009-07-01 Thread ryles
On Jun 29, 5:43 pm, Scott David Daniels wrote: > and I personally wouldn't have it any other way. Simulating a shell > with hooks on its I/O should be so complicated that a "script kiddie" > has trouble writing a Trojan. +1 QOTW -- http://mail.python.org/mailman/listinfo/python-list

Re: Searching equivalent to C++ RAII or deterministic destructors

2009-07-02 Thread ryles
> You can go ahead and implement a __del__() method. It will often work in > CPython, but you get no guarantees, especially when you have reference > cycles and with other Python implementations that don't use refcounting. And for resources whose lifetime is greater than your process (e.g. a file)

Re: Multi thread reading a file

2009-07-02 Thread ryles
On Jul 2, 6:10 am, "Gabriel Genellina" wrote: > En Wed, 01 Jul 2009 12:49:31 -0300, Scott David Daniels   > escribió: > > These loops work well with the two-argument version of iter, > > which is easy to forget, but quite useful to have in your bag > > of tricks: > > >      def convert(in_queue,

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

2009-07-02 Thread ryles
This reminds me. Would anyone object to adding a sentence to http://docs.python.org/library/stringio.html#module-cStringIO just to mention that attributes cannot be added to a cStringIO, like such: % import cStringIO, StringIO % StringIO.StringIO().value = 1 % cStringIO.StringIO().value = 1 Traceb

Re: Adding an object to the global namespace through " f_globals" is that allowed ?

2009-07-02 Thread ryles
On Jul 2, 1:25 am, Terry Reedy wrote: > > The next statement works, > > but I'm not sure if it will have any dramatical side effects, > > other than overruling a possible object with the name A > > > def some_function ( ...) : > > A = object ( ...) > > sys._getframe(1).f_globals [ Name ]

Re: Multi thread reading a file

2009-07-02 Thread ryles
On Jul 2, 10:20 pm, Paul Rubin <http://phr...@nospam.invalid> wrote: > ryles writes: > > >>> # Oh... yeah. I really *did* want 'is None' and not '== None' > > >>> which iter() will do. Sorry guys! > > > Please don't let t

Re: multiprocessing: pool with blocking queue

2009-07-02 Thread ryles
On Jul 2, 11:09 am, masher wrote: > My questions, then, is: Is there a more elegant/pythonic way of doing > what I am trying to do with the current Pool class? Another thing you might try is to subclass Pool and add an apply_async () wrapper which would wait for _taskqueue.qsize() to reach the de

Re: Multi thread reading a file

2009-07-02 Thread ryles
On Jul 2, 11:55 pm, Paul Rubin wrote: > Yeah, it should allow supplying a predicate instead of using == on > a value.  How about (untested): > >    from itertools import * >    ... >    for row in takewhile(lambda x: x is sentinel, >                          starmap(i

Re: how to set timeout while colling a soap method?

2009-07-14 Thread ryles
On Jul 13, 9:07 am, dzizes wrote: > Hello! > > I wrote some some python code for executing a soap method: > > import SOAPpy > from SOAPpy import WSDL > > _server = WSDL.Proxy(some wsdl) > r=_server.generuj(some parameters...) > print r.encode('cp1250') > > It works fine. However, the execution tim

Re: Python Equivalent for dd & fold

2009-07-16 Thread ryles
On Jul 15, 1:14 pm, seldan24 wrote: > On Jul 15, 12:47 pm, Michiel Overtoom wrote: > > > > > seldan24 wrote: > > > what can I use as the equivalent for the Unix 'fold' command? > > > def fold(s,len): > >      while s: > >          print s[:len] > >          s=s[len:] > > > s="A very long string i

Re: difference in printing to screen Mac / Windows

2009-07-24 Thread ryles
On Jul 18, 7:03 am, Tim Chase wrote: > Lastly, you can force all standard-output in your program to be > unbuffered without the "-u" parameter: And if you're using -u a lot, the PYTHONUNBUFFERED environment variable can also be set (but not empty), so that python adds the option automatically. --

Why doesn't `from pkg import mod' work after `del pkg.mod'?

2009-07-24 Thread ryles
According to http://www.python.org/doc/essays/packages.html: "The import statement first tests whether the item is defined in the package; if not, it assumes it is a module and attempts to load it." However, I've noticed that once a module is imported using the `from pkg import mod' syntax, if it

Re: Why doesn't `from pkg import mod' work after `del pkg.mod'?

2009-07-25 Thread ryles
On Jul 25, 8:57 am, Piet van Oostrum wrote: > >>>>> ryles (r) wrote: > >r> According tohttp://www.python.org/doc/essays/packages.html: > >r> "The import statement first tests whether the item is defined in the > >r> package; if not, it ass

Re: Wrapping prstat on Solaris

2009-07-28 Thread ryles
On Jul 27, 10:26 am, s...@pobox.com wrote: > At work we currently use top to monitor ongoing system utilization on our > Solaris systems.  As time has moved on though, use of top has become > problematic.  Our admins want us to switch to prstat, Sun's top-like > command.  It works fine however does

Re: The longest word

2009-07-28 Thread ryles
On Jul 28, 7:55 am, NiklasRTZ wrote: > Sincere thanks for strengthening python's superior flexibility. Same > function also works around an exploding index problem returning > results for longest word where otherwise a word with whitespace > crashes the index: Babelfish? -- http://mail.python.

Re: Is this a bug in multiprocessing or in my script?

2009-08-05 Thread ryles
On Aug 4, 10:37 pm, erikcw wrote: > Traceback (most recent call last): >   File "scraper.py", line 144, in >     print pool.map(scrape, range(10)) >   File "/usr/lib/python2.6/multiprocessing/pool.py", line 148, in map >     return self.map_async(func, iterable, chunksize).get() >   File "/usr/li

Re: Web page data and urllib2.urlopen

2009-08-06 Thread ryles
On Aug 5, 4:30 pm, Massi wrote: > Hi everyone, I'm using the urllib2 library to get the html source code > of web pages. In general it works great, but I'm having to do with a > financial web site which does not provide the souce code I expect. As > a matter of fact if you try: > > import urllib2

Re: unique-ifying a list

2009-08-08 Thread ryles
On Aug 7, 4:53 pm, kj wrote: > Suppose that x is some list.  To produce a version of the list with > duplicate elements removed one could, I suppose, do this: > >     x = list(set(x)) > > but I expect that this will not preserve the original order of > elements. > OrderedSet is most likely on the

Re: How to do relpath implementation on 2.5

2009-08-09 Thread ryles
On Aug 8, 9:08 pm, Brian Allen Vanderburg II wrote: > 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 n

Re: run all scripts in sub-directory as subroutines?

2009-08-12 Thread ryles
On Aug 11, 5:12 pm, guthrie wrote: > This works fine, but in the sub-modules the sys.path appropriately > returns the same as from the parent, I want them to know their own > file names. How?? I can pass it to them, but wondered if there is a > more self-sufficient way for a module to know from wh

Re: Python "and" behavior

2009-08-14 Thread ryles
On Aug 13, 8:36 pm, goldtech wrote: > Could you explain or link me to an explanation of this? http://docs.python.org/tutorial/datastructures.html#more-on-conditions Give the whole tutorial a good read. -- http://mail.python.org/mailman/listinfo/python-list

Re: Splitting a string into substrings of equal size

2009-08-15 Thread ryles
On Aug 14, 8:22 pm, candide wrote: > Suppose you need to split a string into substrings of a given size (except > possibly the last substring). I make the hypothesis the first slice is at the > end of the string. > A typical example is provided by formatting a decimal string with thousands > separ

Re: Splitting a string into substrings of equal size

2009-08-15 Thread ryles
On Aug 15, 6:28 pm, MRAB wrote: > >      >>> for z in ["75096042068045", "509", "12024", "7", "2009"]: > >            print re.sub(r"(?<=.)(?=(?:...)+$)", ",", z) > > >     75,096,042,068,045 > >     509 > >     12,024 > >     7 > >     2,009 > > The call replaces a zero-width match with a comma,

Re: Python 2.6 still not giving memory back to the OS...

2009-08-16 Thread ryles
On Aug 15, 7:55 am, Chris Withers wrote: > Hi All, > > I thought this was fixed back in Python 2.5, but I guess not? > > So, I'm playing in an interactive session: > >  >>> from xlrd import open_workbook >  >>> b = open_workbook('some.xls',pickleable=0,formatting_info=1) > > At this point, top sho

Re: Setuptools - help!

2009-08-19 Thread ryles
On Aug 7, 3:04 pm, Peter Chant wrote: > Robert Kern wrote: > > You need to put main.py into the pphoto package. > > > $ mkdir pphoto/ > > $ mv main.py pphoto/ > > $ touch pphoto/__init__.py > > Thanks, it worked.  Any ideas how to run the resulting scripts without > installing or running as root?

Re: Protecting against callbacks queuing up?

2009-08-24 Thread ryles
On Aug 23, 8:14 pm, Esben von Buchwald wrote: > I thought that this code would do the trick, but it obviously doesn't > help at all, and i can't understand why... > >      def doCallback(self): >          if self.process_busy==False: >              self.process_busy=True >              self.data_c

Re: Object's nesting scope

2009-08-26 Thread ryles
On Aug 26, 8:51 am, zaur wrote: > Hi folk! > > What do you think about idea of "object's nesting scope" in python? > > Let's imaging this feature, for example, in this syntax: > > obj=: >       > > or > > : >     > > That's means that result object of evaluation is used as > nested scope for eva

Re: Q: multiprocessing.Queue size limitations or bug...

2009-08-27 Thread ryles
On Aug 26, 4:56 am, Michael Riedel wrote: > Sorry for being not more specific but I'm not absolutely certain whether > I encountered a bug or did anything wrong: > > The (stupid) code below results in a stall forever or not at 'p0.join()' > depending on the value of TROUBLE_MAKER. > > Any help, th

Re: executable path finding

2009-09-01 Thread ryles
On Aug 31, 12:37 pm, koranthala wrote: > On Aug 31, 9:07 pm, "Diez B. Roggisch" wrote: > > > > > koranthala wrote: > > > Hi, > > >     I am creating a python application using py2exe. I am facing a > > > problem which I am not sure how to solve. > > >     The application contains many other files

Re: Multiple inheritance - How to call method_x in InheritedBaseB from method_x in InheritedBaseA?

2009-09-05 Thread ryles
On Sep 4, 6:01 am, The Music Guy wrote: > I have a peculiar problem that involves multiple inheritance and method > calling. > > I have a bunch of classes, one of which is called MyMixin and doesn't > inherit from anything. MyMixin expects that it will be inherited along > with one of several oth

Re: Is "#!/usr/bin/env python" the better shebang line ?

2009-09-07 Thread ryles
On Sep 6, 10:01 am, Timothy Madden wrote: > Hello > > Sorry if this has been discussed before, my search did not find it. > My questions is if I should use >    #!/usr/bin/env python > as the shebang line in a portable and open python script and if it does > help with portability and usage. Note

Re: simple string question

2009-09-07 Thread ryles
> There's probably a more general method covering all the escape > sequences, but for just \n: > > your_string = your_string.replace("\\n", "\n") py> s = "hello\\r\\n" py> s 'hello\\r\\n' py> s.decode("string_escape") 'hello\r\n' py> -- http://mail.python.org/mailman/listinfo/python-list

Re: Multiple inheritance - How to call method_x in InheritedBaseB from method_x in InheritedBaseA?

2009-09-09 Thread ryles
On Sep 9, 1:47 am, The Music Guy wrote: > I should also mention--and I should have realized this much > sooner--that each of the BaseN classes are themselves each going to > have at least one common base which will define method_x, so each > BaseN will be calling that if it defines its own method_

Re: Multiple inheritance - How to call method_x in InheritedBaseB from method_x in InheritedBaseA?

2009-09-09 Thread ryles
On Sep 9, 7:48 pm, The Music Guy wrote: > Btw, Carl, please forgive me if I frustrate you, because I'm trying my > best not to. I'm trying to keep track of what I did and what you did > and what Ryles and Scott did, while at the same time trying to keep a > firm grasp of

Re: Are min() and max() thread-safe?

2009-09-17 Thread ryles
On Sep 17, 7:02 am, Carl Banks wrote: > On Sep 16, 9:33 pm, Steven D'Aprano > > wrote: > > def minmax(seq): > >     result = [None, None] > >     t1 = MMThread(seq, min, result, 0) > >     t2 = MMThread(seq, max, result, 1) > >     t1.start() > >     t2.start() > >     # Block until all threads a

Re: Granularity of OSError

2009-09-20 Thread ryles
On Sep 19, 9:22 pm, MRAB wrote: > The point is that it's sometimes a good idea to do a cheap check first > before attempting an operation that's 'expensive' even when it fails. Strongly agree. Furthermore, with LBYL it's often easier to give a user clearer error messages for common usage errors,

Re: on package import, have it conditionally import a subpackage

2009-09-20 Thread ryles
pkg/module0.pyc' >  >>> module1.__file__ > 'mybase/mypkg/type1/module1.pyc' >  >>> module2.__file__ > 'mybase/mypkg/type1/module2.pyc' > > but I can't figure out how to do this. > > Thank you, > Gabriel You might try something