Re: autoconf error on Windows

2012-01-29 Thread Chris Rebert
> On Sun, Jan 29, 2012 at 8:07 PM, Chris Rebert wrote: >> On Sun, Jan 29, 2012 at 12:52 AM, Alec Taylor wrote: >>> PyCrypto's install is giving an autoconf error on Windows, whether I >>> install from the git repo or normally. >>> >>> Traceback (

Re: Question about name scope

2012-02-01 Thread Chris Rebert
On Wed, Feb 1, 2012 at 9:11 AM, Olive wrote: > I am learning python and maybe this is obvious but I have not been able > to see a solution. What I would like to do is to be able to execute a > function within the namespace I would have obtained with  from > import * > > For example if I write: >

Re: Generator problem: parent class not seen

2012-02-01 Thread Chris Rebert
On Wed, Feb 1, 2012 at 1:00 PM, Russell E. Owen wrote: > I have an odd and very intermittent problem in Python script. > Occasionally it fails with this error: > > Traceback (most recent call last): >  File > "/Applications/APO/TTUI.app/Contents/Resources/lib/python2.7/TUI/Base/Bas > eFocusScript.

Re: multiple constructor __init__

2012-02-02 Thread Chris Rebert
On Thu, Feb 2, 2012 at 5:09 PM, Emmanuel Mayssat wrote: > Hello all, > > I would like to instantiate my class as follow > > QObject(, ) > QObject() > > an example would be > http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qmenu.html > > How can I do this without have to specify parent=

Re:

2012-02-03 Thread Chris Rebert
On Fri, Feb 3, 2012 at 12:06 PM, Debashish Saha wrote: > would u like to help me by answering some vbasic questions about python? You might prefer to ask such questions on the tutor mailing list instead: http://mail.python.org/mailman/listinfo/tutor Cheers, Chris -- http://mail.python.org/mailm

Re: Common LISP-style closures with Python

2012-02-03 Thread Chris Rebert
On Fri, Feb 3, 2012 at 4:27 PM, Antti J Ylikoski wrote: > > In Python textbooks that I have read, it is usually not mentioned that > we can very easily program Common LISP-style closures with Python.  It > is done as follows: > > - > > # Make a Common LISP-like

Re: MySQLdb not allowing hyphen

2012-02-05 Thread Chris Rebert
On Sun, Feb 5, 2012 at 2:41 PM, Emeka wrote: > > Hello All, > > I noticed that MySQLdb not allowing hyphen may be way to prevent injection > attack. > I have something like below: > > "insert into reviews(message, title)values('%s', '%s')" %( "We don't know > where to go","We can't wait till morro

Re: help function and operetors overloading

2012-02-05 Thread Chris Rebert
On Sun, Feb 5, 2012 at 9:48 PM, Mohsen Pahlevanzadeh wrote: > Dear all, > > You know python has many functions for operators overloading such as > __add__, __radd__, __invert__, __eq__ and so on. > How i see the complete list of them with help function? I don't know if there's a help() entry for

Re: pySerial question, setting certain serial parameters [newbie]

2012-02-06 Thread Chris Rebert
On Sat, Feb 4, 2012 at 4:47 AM, Jean Dupont wrote: > I need to set the following options I found in a Perl-script in Python for > serial communication with a device (a voltmeter): > > $port->handshake("none"); > $port->rts_active(0); > $port->dtr_active(1); > > I have thus far the following  stat

Re: Static HTML documentation from docstrings

2012-02-07 Thread Chris Rebert
On Tue, Feb 7, 2012 at 4:11 AM, Florian Weimer wrote: > I'm slightly confused about docstrings and HTML documentation.  I used > to think that the library reference was (in part) generated from the > source code, but this does not seem to be the case. > > Is there any tool support for keeping docu

Re: Looking for PyPi 2.0...

2012-02-08 Thread Chris Rebert
On Wed, Feb 8, 2012 at 8:54 AM, Nathan Rice wrote: > As a user: > * Finding the right module in PyPi is a pain because there is limited, > low quality semantic information, and there is no code indexing. > * I have to install the module to examine it;  I don't need to look at > docs all the time,

Re: Naming convention for in-house modules (Newbie question)

2012-02-08 Thread Chris Rebert
On Wed, Feb 8, 2012 at 9:15 AM, HoneyMonster wrote: > I am quite new to Python (2.7 on Linux), and have built a few modules > using wxPython/wxGlade for GUI elements and Psycopg2 for database access. > I adhere mostly to the PEP8 guidelines, and use Pylint to help with > quality control. > > So fa

Re: Formate a number with commas

2012-02-09 Thread Chris Rebert
On Thu, Feb 9, 2012 at 12:39 PM, Peter Otten <__pete...@web.de> wrote: > noydb wrote: > >> How do you format a number to print with commas? >> >> Some quick searching, i came up with: >> > import locale > locale.setlocale(locale.LC_ALL, "") > locale.format('%d', 2348721, True) >> '2,348

Re: Formate a number with commas

2012-02-09 Thread Chris Rebert
On Thu, Feb 9, 2012 at 1:16 PM, Peter Otten <__pete...@web.de> wrote: > Chris Rebert wrote: >> On Thu, Feb 9, 2012 at 12:39 PM, Peter Otten <__pete...@web.de> wrote: >>>>>> import locale >>>>>> locale.setlocale(locale.LC_ALL, "

Re: round down to nearest number

2012-02-09 Thread Chris Rebert
On Thu, Feb 9, 2012 at 5:23 PM, noydb wrote: > hmmm, okay. > > So how would you round UP always?  Say the number is 3219, so you want > 3300 returned. http://stackoverflow.com/questions/17944/how-to-round-up-the-result-of-integer-division/96921 Thus: (3219 + 99) // 100 Slight tangent: Beware ne

Re: frozendict

2012-02-10 Thread Chris Rebert
On Fri, Feb 10, 2012 at 8:53 AM, Nathan Rice wrote: > Lets also not forget that knowing an object is immutable lets you do a > lot of optimizations; it can be inlined, it is safe to convert to a > contiguous block of memory and stuff in cache, etc.  If you know the > input to a function is guaran

Re: datetime module and timezone

2012-02-10 Thread Chris Rebert
On Fri, Feb 10, 2012 at 1:25 PM, Olive wrote: > In the datetime module, it has support for a notion of timezone but is > it possible to use one of the available timezone (I am on Linux). Linux > has a notion of timezone (in my distribution, they are stored > in /usr/share/zoneinfo). I would like t

Re: Postpone evaluation of argument

2012-02-10 Thread Chris Rebert
On Fri, Feb 10, 2012 at 3:01 PM, Righard van Roy wrote: > Hello, > > I want to add an item to a list, except if the evaluation of that item > results in an exception. > I could do that like this: > > def r(x): >    if x > 3: >        raise(ValueError) > > try: >    list.append(r(1)) > except: >  

Re: Need help with shutils.copytree

2012-02-12 Thread Chris Rebert
On Sun, Feb 12, 2012 at 12:14 PM, Steven W. Orr wrote: > I have a 'master' directory and a collection of 'slave' dirs. I want the > master to collect all of the stuff in the slave dirs. > > The slaves all look like this, > > . > |-- slaveX > |   `-- archI > |   |   `-- distJ > |   |   |   ` -- FIL

Re: Automatic Type Conversion to String

2012-02-13 Thread Chris Rebert
On Mon, Feb 13, 2012 at 2:01 PM, Bruce Eckel wrote: > I'm creating a class to encapsulate OS paths, to reduce the visual > noise and typing from the os.path methods. I've got the class and nose > tests below, and everything works except the last test which I've > prefixed with XXX: > >    def XXXt

Re: Complexity question on Python 3 lists

2012-02-15 Thread Chris Rebert
On Wed, Feb 15, 2012 at 10:20 AM, Franck Ditter wrote: > What is the cost of calling primes(n) below ? I'm mainly interested in > knowing if the call to append is O(1), even amortized. > Do lists in Python 3 behave like ArrayList in Java (if the capacity > is full, then the array grows by more tha

Re: Complexity question on Python 3 lists

2012-02-15 Thread Chris Rebert
On Wed, Feb 15, 2012 at 10:43 AM, Ian Kelly wrote: > On Wed, Feb 15, 2012 at 11:20 AM, Franck Ditter wrote: >> Do lists in Python 3 behave like ArrayList in Java (if the capacity >> is full, then the array grows by more than 1 element) ? > > I believe the behavior in CPython is that if the array

Re: writing to a file from within nested loops

2012-02-15 Thread Chris Rebert
On Wed, Feb 15, 2012 at 12:12 PM, Rituparna Sengupta wrote: > Hi, > > I'm working on this code and I keep getting an error. It might be some very > basic thing but I was wondering if someone could help. Its a loop within a > loop. The part outside the innermost loop gets printed fine, but the pa

Re: Stand-Alone Python Executable Skeletons

2012-02-15 Thread Chris Rebert
On Wed, Feb 15, 2012 at 2:43 PM, Calvin Spealman wrote: > I've recently been looking into different options to package python > code into stand-alone executables, with tools like Py2EXE and > PyInstaller, but I'm left feeling a little lost. Documentation seems > sparse on all of them, the setups a

Re: Reading sub-string from a file

2012-02-16 Thread Chris Rebert
On Thu, Feb 16, 2012 at 1:52 AM, Smiley 4321 wrote: > All, > > I am a python newbie. > > Let's say I have a filename (test.conf) as below - > > > int Apple(int, int); > void Jump_OnUnload(float, int); > int Jockey_Apple_cat_1KK(float, int, char, int); > int Jockey_Apple_cat_look(int, float, i

Re: signed to unsigned

2012-02-17 Thread Chris Rebert
On Fri, Feb 17, 2012 at 10:51 AM, Brad Tilley wrote: > In C or C++, I can do this for integer conversion: > > unsigned int j = -327681234; // Notice this is signed. > > j will equal 3967286062. I thought with Python that I could use struct > to pack the signed int as an unsigned int, but that fail

Re: netCDF4 variable manipulation

2012-02-21 Thread Chris Rebert
On Tue, Feb 21, 2012 at 12:29 AM, Sheldon wrote: > On Feb 21, 12:53 am, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote: >> On Mon, 20 Feb 2012 12:37:22 -0800, Sheldon wrote: >> > Hi, >> >> > I'm trying to read a netCDF4 variable from a file (no problem) and then >> > scale it before writi

Re: Python math is off by .000000000000045

2012-02-22 Thread Chris Rebert
On Wed, Feb 22, 2012 at 10:13 AM, Alec Taylor wrote: > Simple mathematical problem, + and - only: > 1800.00-1041.00-555.74+530.74-794.95 > -60.9500045 > > That's wrong. Welcome to the world of finite-precision binary floating-point arithmetic then! Reality bites. > Proof > http://ww

Re: Reset static variables or a workaround

2012-02-23 Thread Chris Rebert
On Thu, Feb 23, 2012 at 1:26 AM, Nav wrote: > Hi Guys, > > I have a custom user form class, it inherits my own custom Form class: > > class UserForm(Form): >    first_name = TextField(attributes={id='id_firstname'}) > > Now, everytime UserForm() is instantiated it saves the attributes of > each fo

Re: Just curious: why is /usr/bin/python not a symlink?

2012-02-23 Thread Chris Rebert
On Thu, Feb 23, 2012 at 11:11 AM, Colin Higwell wrote: > $ cd /usr/bin > $ ls -l python* > -rwxr-xr-x 2 root root 9496 Oct 27 02:42 python > lrwxrwxrwx 1 root root    6 Oct 29 19:34 python2 -> python > -rwxr-xr-x 2 root root 9496 Oct 27 02:42 python2.7 > $ diff -s  python python2.7 > Files python

Re: sum() requires number, not simply __add__

2012-02-23 Thread Chris Rebert
On Thu, Feb 23, 2012 at 1:19 PM, Buck Golemon wrote: > I feel like the design of sum() is inconsistent with other language > features of python. Often python doesn't require a specific type, only > that the type implement certain methods. > > Given a class that implements __add__ why should sum()

Re: namespace question

2012-02-23 Thread Chris Rebert
On Thu, Feb 23, 2012 at 9:55 PM, xixiliguo wrote: > c = [1, 2, 3, 4, 5] > class TEST(): >    c = [5, 2, 3, 4, 5] That line creates a class (i.e. "static") variable, which is unlikely to be what you want. Instance variables are normally created in the body of an __init__() method. >    def add( s

Re: subtraction of floating point numbers

2012-02-24 Thread Chris Rebert
On Fri, Feb 24, 2012 at 12:41 AM, Jaroslav Dobrek wrote: > Hello, > > when I have Python subtract floating point numbers it yields weird > results. Example: > > 4822.40 - 4785.52 = 36.87992 > > Why doesn't Python simply yield the correct result? It doesn't have a > problem with this: > > 4

Re: How to handle calling functions from cli

2012-02-24 Thread Chris Rebert
On Fri, Feb 24, 2012 at 2:16 PM, Rodrick Brown wrote: > I have a bunch of sub routines that run independently to perform various > system checks on my servers. I wanted to get an opinion on the following code > I have about 25 independent checks and I'm adding the ability to disable > certain c

Re: pickle handling multiple objects ..

2012-02-26 Thread Chris Rebert
On Sun, Feb 26, 2012 at 3:25 AM, Smiley 4321 wrote: > If I have a sample python code to be executed on Linux. How should  I handle > multiple objects with 'pickle' as below - > > --- > #!/usr/bin/python > > import pickle > > #my_list = {'a': 'Apple', 'b': 'Mango', 'c': 'Orange', 'd': 'Pineappl

Re: How can I make an instance of a class act like a dictionary?

2012-02-26 Thread Chris Rebert
On Sun, Feb 26, 2012 at 11:24 PM, John Salerno wrote: > Hi everyone. I created a custom class and had it inherit from the > "dict" class, and then I have an __init__ method like this: > > def __init__(self): >        self = create() > > The create function creates and returns a dictionary object.

Re: Listing children processes

2012-02-28 Thread Chris Rebert
On Tue, Feb 28, 2012 at 10:33 AM, Mihai Badoiu wrote: > I'm trying to compute the total CPU load of an external process and it's > children.  (so I cannot use resource.getrusage)  For the load of the process > I can just grab it from /proc/X/stat.  How do I get the CPU load of the > children proce

Re: list comprehension question

2012-02-29 Thread Chris Rebert
On Wed, Feb 29, 2012 at 5:52 AM, Johann Spies wrote: > I understand the following: > > In [79]: instansie > instansie > Out[79]: 'Mangosuthu Technikon' > > In [80]: t = [x.alt_name for x in lys] > t = [x.alt_name for x in lys] > > In [81]: t > t > Out[81]: [] > > In [82]: t.append(instansie) > t.a

Re: Help needed: dynamically pull data from different levels of a dict

2012-02-29 Thread Chris Rebert
On Wed, Feb 29, 2012 at 7:56 PM, Peter Rubenstein wrote: > Hi, > > I'd appreciate a bit of help on this problem.  I have some data that I've > converted to a dict and I want to pull out individual pieces of it. > > Simplified version-- > > a={'1':'a', '2':'b', '3':{4:'d'}, '5':{'6': {'7': [ {'8':'

Re: Spacing and timing for comparing algorithms and data-structures

2012-03-01 Thread Chris Rebert
On Thu, Mar 1, 2012 at 8:55 PM, Alec Taylor wrote: > What would you recommend I use to compare data-structures and > algorithms on space and time? (runtime) For the latter metric, one of the profiling modules: http://docs.python.org/library/debug.html I'd start with timeit and go from there: http

Re: Is this the proper way to use a class method?

2012-03-01 Thread Chris Rebert
On Thu, Mar 1, 2012 at 10:00 PM, John Salerno wrote: > This is purely for fun and learning, so I know there are probably better ways > of creating a chess program. Right now I'm just curious about my specific > question, but I'd love to hear any other advice as well. > > Basically, I'm wondering

Re: Is this the proper way to use a class method?

2012-03-02 Thread Chris Rebert
On Thu, Mar 1, 2012 at 11:16 PM, John Salerno wrote: >> That's just a coincidence. Your supercall is ought to be: super().move() >> In contrast, super().move(self) calls the superclass instance method >> `move` with 2 arguments, both `self`, which just happens to work given >> your move() method,

Re: decompilation

2012-03-02 Thread Chris Rebert
On Fri, Mar 2, 2012 at 10:52 AM, shikha panghal wrote: > Hi > > Please decoplile the .pyc code ,as i have lost my .py code. Your best shot would be: http://www.crazy-compilers.com/decompyle/ Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Re: Python - CGI-BIN - Apache Timeout Problem

2012-03-02 Thread Chris Rebert
On Fri, Mar 2, 2012 at 12:09 PM, Sean Cavanaugh (scavanau) wrote: > THE PROBLEM: > > When I execute the scripts from the command line (#python main.py) it > generates it fine (albeit slowly), it prints all the html code out including > the script.  The ‘core’ part of the script dumbed down to the

Re: The original command python line

2012-03-03 Thread Chris Rebert
On Sat, Mar 3, 2012 at 9:38 PM, Damjan Georgievski wrote: > How can I get the *really* original command line that started my python > interpreter? > > Werkzeug has a WSGI server which reloads itself when files are changed > on disk. It uses `args = [sys.executable] + sys.argv` to kind of > recreat

Re: The original command python line

2012-03-03 Thread Chris Rebert
On Sat, Mar 3, 2012 at 9:48 PM, Chris Rebert wrote: > On Sat, Mar 3, 2012 at 9:38 PM, Damjan Georgievski wrote: >> How can I get the *really* original command line that started my python >> interpreter? > On Linux, you can read from: >    /proc//cmdline > to get the null

Re: Is this the right location to launch IDLE?

2012-03-04 Thread Chris Rebert
On Sun, Mar 4, 2012 at 3:07 PM, John Salerno wrote: > I'm trying to get Notepad++ to launch IDLE and run the currently open file in > IDLE, but all my attempts have failed so far. I'm wondering, am I even using > the IDLE path correctly? I'm using this: > > "C:\Python32\Lib\idlelib\idle.pyw" "$(

Re: Is this the right location to launch IDLE?

2012-03-04 Thread Chris Rebert
On Sun, Mar 4, 2012 at 7:51 PM, John Salerno wrote: > Unfortunately neither method worked. Adding "-r" to the path created this > error when I tried it: > > *** Error in script or command! > > Traceback (most recent call last): >  File "C:\Users\John\Documents\Python Scripts\chess_pieces.py"

Re: What's the best way to write this regular expression?

2012-03-06 Thread Chris Rebert
On Tue, Mar 6, 2012 at 2:43 PM, John Salerno wrote: > I sort of have to work with what the website gives me (as you'll see below), > but today I encountered an exception to my RE. Let me just give all the > specific information first. The point of my script is to go to the specified > URL and e

Re: Python site-packages permission denied?

2012-03-07 Thread Chris Rebert
On Wed, Mar 7, 2012 at 1:02 PM, Shane Neeley wrote: > What do I need to do to successfully install a package onto python so that I > can use it as a module? > > I have tried in terminal in the correct directory "python2.7 ./setup.py > install" but it says permission denied. > > Shanes-MacBook-Pr

Re: newb __init__ inheritance

2012-03-11 Thread Chris Rebert
On Sun, Mar 11, 2012 at 3:18 AM, hyperboogie wrote: > thank you everyone... > Still things are not working as expected... what am I doing wrong? > # cat test.py > #!/usr/bin/python > > class A(): You should be subclassing `object`, but that's a minor point which isn't the cause of your problem.

Re: newb __init__ inheritance

2012-03-11 Thread Chris Rebert
On Sun, Mar 11, 2012 at 3:56 AM, hyperboogie wrote: > On Sunday, March 11, 2012 12:38:27 PM UTC+2, Chris Rebert wrote: >> On Sun, Mar 11, 2012 at 3:18 AM, hyperboogie wrote: >> >> > thank you everyone... >> > Still things are not working as expected... what

Re: Raise X or Raise X()?

2012-03-11 Thread Chris Rebert
On Sun, Mar 11, 2012 at 1:37 PM, Irmen de Jong wrote: > On 11-3-2012 20:04, bvdp wrote: >> Which is preferred in a raise: X or X()? I've seen both. In my specific case >> I'm dumping out of a deep loop: >> >> try: >>   for ... >>     for ... >>       for ... >>         if match: >>            rai

Re: concatenate function

2012-03-13 Thread Chris Rebert
On Tue, Mar 13, 2012 at 1:35 PM, Robert Kern wrote: > On 3/13/12 6:01 PM, ferreirafm wrote: >> Robert Kern-2 wrote >>> When you report a problem, you should copy-and-paste the output that you >>> got and >>> also state the output that you expected. I have no idea what you mean >>> when >>> you >>>

Re: Global join function?

2012-03-14 Thread Chris Rebert
On Wed, Mar 14, 2012 at 11:41 AM, Darrel Grant wrote: > In the virtualenv example bootstrap code, a global join function is used. > > http://pypi.python.org/pypi/virtualenv > >    subprocess.call([join(home_dir, 'bin', 'easy_install'), >                     'BlogApplication']) > > > In interpeter,

Re: Python simulate browser activity

2012-03-15 Thread Chris Rebert
On Thu, Mar 15, 2012 at 7:23 PM, choi2k wrote: > Hi, everyone > > I am trying to write a small application using python but I am not > sure whether it is possible to do so.. > The application aims to simulate user activity including visit a > website and perform some interactive actions (click on

Re: Why not use juxtaposition to indicate function application

2012-03-16 Thread Chris Rebert
On Fri, Mar 16, 2012 at 1:57 PM, Serhiy Storchaka wrote: > 16.03.12 18:45, Steven D'Aprano написав(ла): >> If f is a function which normally takes (for the sake of the argument) >> one argument, then f would call the function with no arguments (which may >> return a curried function, or may apply

Re: How to get a reference of the 'owner' class to which a method belongs in Python 3.X?

2012-03-16 Thread Chris Rebert
On Fri, Mar 16, 2012 at 10:30 PM, Cosmia Luna wrote: > I'm porting my existing work to Python 3.X, but... > > class Foo: >    def bar(self): >        pass > > mthd = Foo.bar > > assert mthd.im_class is Foo # this does not work in py3k > > So, how can I get a reference to Foo? This is important whe

Re: Python is readable

2012-03-18 Thread Chris Rebert
On Sun, Mar 18, 2012 at 8:15 PM, alex23 wrote: > John Ladasky wrote: >> > The idea that Python code has to be obvious to non-programmers is an >> > incorrect and dangerous one. >> >> Incorrect?  Probably.  Dangerous?  You'll have to explain what you >> mean. > > The classic "obvious" behaviour to

Re: New learner of Python--any suggestion on studying it?

2012-03-19 Thread Chris Rebert
On Sun, Mar 18, 2012 at 11:30 PM, yan xianming wrote: > Hello all, > > I'm a new learning of Python. > > Can someone give me some suggestion about it? http://docs.python.org/tutorial/index.html http://wiki.python.org/moin/BeginnersGuide/NonProgrammers http://wiki.python.org/moin/BeginnersGuide/Pr

Re: Python is readable

2012-03-21 Thread Chris Rebert
On Tue, Mar 20, 2012 at 11:52 PM, Steve Howell wrote: > On Mar 20, 10:40 pm, Chris Angelico wrote: >> On Wed, Mar 21, 2012 at 3:58 PM, Steve Howell wrote: >> > So saying "push(stack, item)" or "push(item, stack)" seems very >> > unsophisticated, almost assembly-like in syntax, albeit at a higher

Re: class checking its own module for an attribute

2012-03-21 Thread Chris Rebert
On Wed, Mar 21, 2012 at 8:25 AM, Rod Person wrote: > The question is there a way I can do this with out having to import > constants when what it's doing is importing itself. It would seem to me > that there should be a way for a module to reference itself. In that > thinking I have tried > >  if

Re: Best way to disconnect from ldap?

2012-03-21 Thread Chris Rebert
On Wed, Mar 21, 2012 at 12:30 PM, John Gordon wrote: > I'm writing an application that interacts with ldap, and I'm looking > for advice on how to handle the connection.  Specifically, how to > close the ldap connection when the application is done. > > I wrote a class to wrap an LDAP connection,

Re: Python classes: Simplify?

2012-03-22 Thread Chris Rebert
On Thu, Mar 22, 2012 at 3:51 AM, Steven Lehar wrote: > It seems to me that the Python class system is needlessly confusing. Am I > missing something? Explicit `self` is slightly annoying, but you'll get over it quickly (trust me). > For example in the class Complex given in the documentation > >

Re: Accessing the files by last modified time

2012-03-22 Thread Chris Rebert
On Thu, Mar 22, 2012 at 4:33 AM, Sangeet wrote: > Hi > > I am new to the python programming language. > > I've been trying to write a script that would access the last modified file > in one of my directories. I'm using Win XP. > > I saw a similar topic, on the forum before, however the reply usi

Re: Best way to disconnect from ldap?

2012-03-22 Thread Chris Rebert
On Thu, Mar 22, 2012 at 6:14 AM, Tycho Andersen wrote: > On Wed, Mar 21, 2012 at 04:49:54PM -0500, Tim Chase wrote: >> On 03/21/12 15:54, Chris Kaynor wrote: >> >As Chris Rebert pointed out, there is no guarantee as to when the >> >__del__ method is called. CPy

Re: Good web-development Python book

2012-03-23 Thread Chris Rebert
On Fri, Mar 23, 2012 at 9:16 AM, Yves S. Garret wrote: > Oooops!  Sent my previous e-mail too soon!  Didn't mean to. > > Another try. > > Hello, > >   I'm trying to brush up on my Python and would like to learn how to > make web-apps.  I was hoping to get a good book on learning how to > make web-

Re: Good web-development Python book

2012-03-23 Thread Chris Rebert
On Fri, Mar 23, 2012 at 10:13 AM, Dennis Lee Bieber wrote: > On Fri, 23 Mar 2012 09:30:24 -0700, Chris Rebert > declaimed the following in gmane.comp.python.general: > >> On Fri, Mar 23, 2012 at 9:16 AM, Yves S. Garret >> wrote: >         >> > make web-applica

Re: string interpolation for python

2012-03-31 Thread Chris Rebert
On Fri, Mar 30, 2012 at 11:22 PM, Yingjie Lan wrote: > Hi all, > > I'd really like to share this idea of string interpolation for formatting. > Let's start with some code: > name = "Shrek" print( "Hi, $name$!") > Hi, Shrek! Python already has *3* different built-in string formatting/int

Re: Tkinter: IDLE can't get out of mainloop

2012-03-31 Thread Chris Rebert
On Sat, Mar 31, 2012 at 12:42 AM, Frederic Rentsch wrote: >   If I run from a terminal things seem to work out. Is it standard > development practice to run code from a terminals ($ python program.py)? > What's the 'program.pyc' for if the source is compiled every time? The entire point of .pyc

Re: string interpolation for python

2012-04-02 Thread Chris Rebert
On Mon, Apr 2, 2012 at 2:11 AM, Yingjie Lan wrote: > I believe non of the other three alternatives are as terse and readable. > We've got template based, formatting with dict, formatting with tuple. > They all require the coder extra effort: > > Both template based and dict-based formatting requi

Re: How I can draw the grid lines at intervals with step=1?

2012-04-02 Thread Chris Rebert
On Mon, Apr 2, 2012 at 5:14 PM, Andres Soto wrote: > Hi > I am trying to draw a step (or staircase) function. My points are all > integers. I would like that the grid lines help to identify the limits of > each line, but when I draw the grid, it is set each 5 units. > How can I draw the grid lines

Re: produce the same output as Unix's date command

2012-04-05 Thread Chris Rebert
On Thu, Apr 5, 2012 at 1:52 PM, Jabba Laci wrote: > Hi, > > Unix's date command produces this output (example): > > Thu Apr  5 22:49:42 CEST 2012 > > I would like to produce the same output with Python, without calling > "date" externally. Before doing it I'd like to ask the list if anyone > has a

Re: Reading Live Output from a Subprocess

2012-04-06 Thread Chris Rebert
On Thu, Apr 5, 2012 at 11:57 PM, wrote: > Okay, I've been trying for days to figure this out, posting on forums, > Googling, whatever. I have yet to find a solution that has worked for me. > (I'm using Python 3.2.2, Ubuntu 11.04.) Everything I've tried has led to > buffered output being spat b

Re: Pass a list of variables to a procedure

2012-04-07 Thread Chris Rebert
On Sat, Apr 7, 2012 at 2:15 PM, KRB wrote: > Hi there, > > I would like to be able to pass a list of variables to a procedure, and have > the output assigned to them. You cannot pass a variable itself to a function; you can only pass a variable's value. Which is to say that Python doesn't use pa

Re: ast.parse

2012-04-09 Thread Chris Rebert
On Mon, Apr 9, 2012 at 4:53 AM, Kiuhnm wrote: > Is it a known fact that ast.parse doesn't handle line continuations and some > multi-line expressions? > For instance, he doesn't like >    for (x, >         y) in each([1, >                     2]): >        print(1) > at all. > Is there a workaroun

Re: How to stop the program as soon as one of the condition is met

2012-04-16 Thread Chris Rebert
On Mon, Apr 16, 2012 at 12:06 PM, Chinesekidz wrote: > Hello Guys: > > How can I stop the program as soon as one of the condition is met? > > > Here is example: > > The loop should be stop asking for more input if a=b or c=6. > > I tried to write one but it only stop when a=b and not when c=6 Ple

Re: Suggest design to accomodate non-unix platforms ?

2012-04-18 Thread Chris Rebert
On Wed, Apr 18, 2012 at 6:35 AM, Richard Shea wrote: > On a *nix box this is a reasonable bit of Python : > > cmd = "ssh -o StrictHostKeyChecking=no -i %s %s@%s '%s' > %s" % (key, > user, dns, "echo CONNECTION READY", tmp_file) > result = os.system(cmd) It's slightly less reasonable considering t

Re: This code not working, need suggetions

2012-04-23 Thread Chris Rebert
On Sun, Apr 22, 2012 at 11:16 PM, Anirudh Srinivasan wrote: > > My code lists the files and directory under a folder and if we want to > read the file it uses the function  cat. > > But the function cat(get_file) is not working , any suggetions? Please specifically state exactly how it's deviatin

Re: I couldn't use the sign funcion inside of another function

2012-04-23 Thread Chris Rebert
On Mon, Apr 23, 2012 at 11:29 AM, Julio Sergio wrote: > I want to use the sign function. When I use it in in-line mode works pretty > well: > >   : sign(-20) >   : -1 > > However, I wrote the following code in a file, say, pp.py > > def tst(x): >    s = sign(x) >    return(s) > > Then I tried to i

Re: Half-baked idea: list comprehensions with "while"

2012-04-26 Thread Chris Rebert
On Thu, Apr 26, 2012 at 10:02 AM, Roy Smith wrote: > I'm not seriously suggesting this as a language addition, just an interesting > idea to simplify some code I'm writing now: > > x = [a for a in iterable while a] > > which equates to: > > x = [] > for a in iterable: >    if not a: >        brea

Re: confusing doc: mutable and hashable

2012-04-28 Thread Chris Rebert
On Sat, Apr 28, 2012 at 11:09 AM, wrote: > I'm just learning Python. The python doc about mutable and hashable is > confusing to me. > > In my understanding, there is no directly relation between mutable and > hashable in Python. Any class with __hash__ function is "hashable". > > According the

Re: convert integer to string

2012-04-29 Thread Chris Rebert
On Sun, Apr 29, 2012 at 10:18 AM, Andres Soto wrote: > I have already import string from string import * > but I can not still convert an integer to string There is no need to import the `string` module to do that. Most of the `string` module is deprecated. `str` is the *built-in* type

Re: Creating a directory structure and modifying files automatically in Python

2012-04-30 Thread Chris Rebert
On Mon, Apr 30, 2012 at 8:19 AM, wrote: > Hi, > > I would like to automate the following task under Linux. I need to create a > set of directories such as > > 075 > 095 > 100 > 125 > > The directory names may be read from a text file foobar, which also contains > a number corresponding to each

Re: DateTime objectFormatting

2012-05-02 Thread Chris Rebert
On Wed, May 2, 2012 at 7:49 AM, Nikhil Verma wrote: >     def __unicode__(self): >     return "%s %s" % (self.name, self.date_created.strftime("%A %B %d")) > > > The user fills Gen GI in name and date along with time. > > What i am able to achieve with this class object to return is :- > > Ge

Re: sorting 1172026 entries

2012-05-06 Thread Chris Rebert
On Sun, May 6, 2012 at 9:29 AM, J. Mwebaze wrote: > sorry see, corrected code > > > for filename in txtfiles: >    temp=[] >    f=open(filename) Why not use `with` here too? >    for line in f.readlines(): readlines() reads *the entire file contents* into memory all at once! Use `for line in f:

Re: sorting 1172026 entries

2012-05-06 Thread Chris Rebert
On Sun, May 6, 2012 at 4:54 PM, Cameron Simpson wrote: > On 06May2012 18:36, J. Mwebaze wrote: > | > for filename in txtfiles: > | >    temp=[] > | >    f=open(filename) > | >    for line in f.readlines(): > | >      line = line.strip() > | >      line=line.split() > | >      temp.append((parser.

Re: indexed property? Can it be done?

2012-05-07 Thread Chris Rebert
On Mon, May 7, 2012 at 8:15 PM, Charles Hixson wrote: > class Node: > >    def    __init__(self, nodeId, key, value, downRight, downLeft, parent): >        dirty    =    True >        dlu    =    utcnow() >        self.node    =    [nodeId, downLeft, [key], [value], [downRight], > parent, dirty, d

Re: How to get outer class name from an inner class?

2012-05-08 Thread Chris Rebert
On Tue, May 8, 2012 at 1:05 PM, John Gordon wrote: > I'm trying to come up with a scheme for organizing exceptions in > my application. > > Currently, I'm using a base class which knows how to look up the text > of a specific error in a database table, keyed on the error class name. > > The base c

Re: tee-like behavior in Python

2012-05-09 Thread Chris Rebert
On Wed, May 9, 2012 at 8:35 AM, Florian Lindner wrote: > Hello, > > how can I achieve a behavior like tee in Python? > > * execute an application > * leave the output to stdout and stderr untouched > * but capture both and save it to a file (resp. file-like object) > > I have this code > > proc =

Re: Hashability questions

2012-05-14 Thread Chris Rebert
On Sun, May 13, 2012 at 12:11 PM, Bob Grommes wrote: > Noob alert: writing my first Python class library. > > I have a straightforward class called Utility that lives in Utility.py. > > I'm trying to get a handle on best practices for fleshing out a library.  As > such, I've done the following fo

Re: How to embed python2 into python3?

2012-05-16 Thread Chris Rebert
On Wed, May 16, 2012 at 7:59 AM, ytj wrote: > Hello, all: > > I have two programs, one is written in py3k, the other is written in > python 2. I am wondering how to make them work together except port > the python 2 code to py3k? Porting the Python 3 code to Python 2 is also an option: http://pyp

Re: Newbie questions on import & cmd line run

2012-05-16 Thread Chris Rebert
On Wed, May 16, 2012 at 6:45 PM, gwhite wrote: > Hi, > > I am a newbie running the latest pythonxy (2.7.2.1) & spyder and > python 2.7.2.   I suspect my questions are mostly basic to python, and > not specific to Spyder or iPython. > > Note: Up until now, I mainly used MATLAB, and thus need to de-

Re: bash/shell to python

2012-05-17 Thread Chris Rebert
On Wed, May 16, 2012 at 7:16 PM, Rita wrote: > Hello, > > I currently build a lot of interfaces/wrappers to other applications using > bash/shell. One short coming for it is it lacks a good method to handle > arguments so I switched to python a while ago to use 'argparse' module. Its > a great com

Re: serial module

2012-05-18 Thread Chris Rebert
On Fri, May 18, 2012 at 2:53 PM, Ron Eggler wrote: > Hoi, > > I'm trying to connect to a serial port and always get the error > "serial.serialutil.SerialException: Port is already open." whcih is untrue. > I have no serial port open yet, my code looks like this: > #!/usr/bin/python > import time >

Re: Scoping Issues

2012-05-24 Thread Chris Rebert
On Thu, May 24, 2012 at 6:23 PM, SherjilOzair wrote: > def adder(): >        s = 0 >        def a(x): Add a "nonlocal s" declaration right here. See http://www.python.org/dev/peps/pep-3104/ >            s += x >            return sum >        return a > > pos, neg = adder(), adder() > for i in r

Re: Object cleanup

2012-05-30 Thread Chris Rebert
On Wed, May 30, 2012 at 9:40 AM, Steven D'Aprano wrote: > On Wed, 30 May 2012 09:01:20 -0700, psaff...@googlemail.com wrote: > >> However, I've found that using guppy, after the methods have returned >> most of the memory is being taken up with BeautifulSoup objects of one >> type or another. I'm

Re: understanding operator overloading

2012-06-01 Thread Chris Rebert
On Fri, Jun 1, 2012 at 9:39 AM, Josh Benner wrote: > > Is there a good way to trace what's going on under the hood wrt operator > overloading? > > I am trying to understand what is happening in the code and output listed > below. > > Why doesn't __getitem__ in mylist return the same result as the

Re: Installing Mailman

2012-06-03 Thread Chris Rebert
On Sun, Jun 3, 2012 at 9:04 PM, Janet Heath wrote: > checking for --with-python... no > checking for python... /usr/bin/python > checking Python interpreter... /usr/bin/python > checking Python version... 2.7.1 > checking Python's email package... ok > checking Japanese codecs... ok > checking Kor

Re: file pointer array

2012-06-04 Thread Chris Rebert
On Mon, Jun 4, 2012 at 6:21 PM, FSH wrote: > Hello, > > I have a simple question. I wish to generate an array of file > pointers. For example, I have files: > > data1.txt > data2.txt > data3.txt > > > I wish to generate fine pointer array so that I can read the files at > the same time. > > f

<    1   2   3   4   5   6   7   8   9   10   >