Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.

2010-02-20 Thread Jonathan Gardner
On Fri, Feb 19, 2010 at 11:16 PM, Lie Ryan wrote: > > Now, why don't we start a PEP to make python a fully-functional language > then? > Because people don't think the same way that programs are written in functional languages. -- Jonathan Gardner jgard...@jonathangardner.net -- http://mail.py

Re: Capturing errors raised by other scripts ?

2010-02-20 Thread Lie Ryan
On 02/20/10 14:39, northof40 wrote: > On Feb 20, 4:13 pm, MRAB wrote: >> northof40 wrote: >>> I'm using the subroutine module to run run python script A.py from >>> B.py (this is on windows fwiw). >> >>> A.py is not my script and it may raise arbitary errors before exiting. >>> How can I determine

Re: Can't Access ANY url from python (errno 61)

2010-02-20 Thread MattB
On Feb 20, 2:02 am, Lie Ryan wrote: > On 02/20/10 13:32, MattB wrote: > > > > > I'm using the network in my own apartment. Not the campus's. > > Moreover, my mac's MAC address is different from the MAC address shown > > by my router, but as I said I'm also blocked when using my friend's > > wirele

Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.

2010-02-20 Thread Chris Rebert
On Fri, Feb 19, 2010 at 11:17 PM, sjdevn...@yahoo.com wrote: > On Feb 20, 1:30 am, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> If Python doesn’t distinguish between procedures and functions, why should >> it distinguish between statements and expressions? > > Because the latter are dif

Re: Can't Access ANY url from python (errno 61)

2010-02-20 Thread Shashwat Anand
throw up your 'ifconfig' and mozilla-proxy output here. It seems you don't know whether you are using proxy. For mozilla proxy : open mozilla -> cmd + "," -> Network -> Settings -> Paste everything that is there/ may be take a snapshot and upload a link. ~l0nwlf On Sat, Feb 20, 2010 at 2:06 PM,

os.pipe() + os.fork()

2010-02-20 Thread Sebastian Noack
Hi, I have a problem using os.pipe() together with os.fork(). Usually when the writing end of the pipe is closed, the reading end gets EOF. So subsequent attempts to read data will return an empty string. But when you call os.fork() after you have created a pipe using os.pipe(), and read data from

Re: Avoid converting functions to methods in a class

2010-02-20 Thread Arnaud Delobelle
On 20 Feb, 03:33, Steven D'Aprano wrote: > I have a convention when writing unit tests to put the target of the test > into a class attribute, as follows: > > class MyTest(unittest.TestCase): >     target = mymodule.someclass > >     def test_spam(self): >         """Test that someclass has a spam

Re: Scalable python dict {'key_is_a_string': [count, some_val]}

2010-02-20 Thread Arnaud Delobelle
On 20 Feb, 06:36, krishna wrote: > I have to manage a couple of dicts with huge dataset (larger than > feasible with the memory on my system), it basically has a key which > is a string (actually a tuple converted to a string) and a two item > list as value, with one element in the list being a co

Precision issue in python

2010-02-20 Thread mukesh tiwari
Hello everyone. I think it is related to the precision with double arithmetic so i posted here.I am trying with this problem (https:// www.spoj.pl/problems/CALCULAT) and the problem say that "Note : for all test cases whose N>=100, its K<=15." I know precision of doubles in c is 16 digits. Could s

Shared web host good citizenship question

2010-02-20 Thread Carl Banks
Not specifically Python related but thought I'd ask. If you have a low-bandwidth website running on a shared web hosting service as a WSGI server (or FastCGI, or any other interface with its own process), is it considered a responsible thing for the process to exit on its own after a period of non

Re: os.pipe() + os.fork()

2010-02-20 Thread Sebastian Noack
I have figured out that, you have to close the writing end in the child process, which is reading from the pipe. Otherwise the underlying pipe is not going to be closed when the parent process is closing its writing end. This has nothing to do with Python itself. I have tried plain C and there it i

Re: Precision issue in python

2010-02-20 Thread Mark Dickinson
On Feb 20, 11:17 am, mukesh tiwari wrote: > Hello everyone. I think it is  related to the precision with double > arithmetic so i posted here.I am trying with this problem > (https://www.spoj.pl/problems/CALCULAT) and the problem say that "Note : for > all test cases whose N>=100, its K<=15." I k

Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.

2010-02-20 Thread Michael Sparks
On Feb 18, 4:15 pm, Steve Howell wrote: ... >     def print_numbers() >         [1, 2, 3, 4, 5, 6].map { |n| >             [n * n, n * n * n] >         }.reject { |square, cube| >             square == 25 || cube == 64 >         }.map { |square, cube| >             cube >         }.each { |n| >  

Re: Precision issue in python

2010-02-20 Thread Shashwat Anand
A quick solution I came out with, no stirling numbers and had tried to avoid large integer multiplication as much as possible. import math for i in range(int(raw_input())): n, k, l = [int(i) for i in raw_input().split()] e = sum(math.log10(i) for i in range(1, n+1)) frac_e = e - math.

Re: Looking for crossfold validation code

2010-02-20 Thread Sandy
Following is the code I use. I got it from web, but forgot the link. def k_fold_cross_validation(X, K, randomise = False): """ Generates K (training, validation) pairs from the items in X. Each pair is a partition of X, where validation is an iterable of length len

Re: Precision issue in python

2010-02-20 Thread mukesh tiwari
On Feb 20, 5:44 pm, Mark Dickinson wrote: > On Feb 20, 11:17 am, mukesh tiwari > wrote: > > > Hello everyone. I think it is  related to the precision with double > > arithmetic so i posted here.I am trying with this problem > > (https://www.spoj.pl/problems/CALCULAT) and the problem say that "No

Re: Few questions on SOAP

2010-02-20 Thread Muhammad Alkarouri
Thanks every one for commenting. I guess I misspoke. I meant to say that the group is not necessarily the best for parts of this question, so Subhabrata might not get as enthusiastic responses as in some other lists (which i don't recollect at the moment, sorry). I didn't want to convey the sense t

Re: Precision issue in python

2010-02-20 Thread mukesh tiwari
On Feb 20, 8:13 pm, mukesh tiwari wrote: > On Feb 20, 5:44 pm, Mark Dickinson wrote: > > > > > > > On Feb 20, 11:17 am, mukesh tiwari > > wrote: > > > > Hello everyone. I think it is  related to the precision with double > > > arithmetic so i posted here.I am trying with this problem > > > (htt

Re: Precision issue in python

2010-02-20 Thread Shashwat Anand
> I don't know if is possible to import this decimal module but kindly > tell me.Also a bit about log implementation > Why don't you read about decimal module (there is log too in it) and try writing your approach here in case it does not work? Or you insist someone to rewrite your code using decim

Pure virtual functions in Python?

2010-02-20 Thread lallous
Hello How can I do something similar to pure virtual functions in C++ ? Let us consider this: class C1: # Pure virtual def cb(self, param1, param2): """ This is a callback @param param1: ... @param param2: ... """ raise NotImplementedErro

finding element by tag in xml

2010-02-20 Thread sWrath swrath
Hi I am trying to search an element by tag and new in reading a xml file (in python). I coded this , but it did not work -- '''This is to detect the first element and print out all that element by tag''' from xml.dom.minidom import parse from xml.etre

Re: Upgrading Py2exe App

2010-02-20 Thread T
On Feb 19, 4:32 pm, Ryan Kelly wrote: > On Fri, 2010-02-19 at 11:08 -0800, T wrote: > > On Feb 18, 7:19 pm, Ryan Kelly wrote: > > > On Thu, 2010-02-18 at 07:46 -0800, T wrote: > > > > I have a Python app which I converted to an EXE (all files separate; > > > > single EXE didn't work properly) via

Re: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.

2010-02-20 Thread Steve Howell
On Feb 20, 6:13 am, Michael Sparks wrote: > On Feb 18, 4:15 pm, Steve Howell wrote: > ... > > >     def print_numbers() > >         [1, 2, 3, 4, 5, 6].map { |n| > >             [n * n, n * n * n] > >         }.reject { |square, cube| > >             square == 25 || cube == 64 > >         }.map {

Re: Pure virtual functions in Python?

2010-02-20 Thread Martin v. Loewis
lallous wrote: > Hello > > How can I do something similar to pure virtual functions in C++ ? See, for example http://code.activestate.com/recipes/266468/ Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: Pure virtual functions in Python?

2010-02-20 Thread Diez B. Roggisch
Am 20.02.10 17:12, schrieb lallous: Hello How can I do something similar to pure virtual functions in C++ ? Let us consider this: class C1: # Pure virtual def cb(self, param1, param2): """ This is a callback @param param1: ... @param param2: ...

Re: Pure virtual functions in Python?

2010-02-20 Thread Martin v. Loewis
>> class C1: >> >> # Pure virtual >> def cb(self, param1, param2): >> """ >> This is a callback >> >> @param param1: ... >> @param param2: ... >> """ >> raise NotImplementedError, "Implement me" >> >> # Dispatcher function that calls '

Re: Pure virtual functions in Python?

2010-02-20 Thread Diez B. Roggisch
Sorry, I totally mis-read the OP, too tired. You are right of course. Diez -- http://mail.python.org/mailman/listinfo/python-list

Re: Pure virtual functions in Python?

2010-02-20 Thread Rami Chowdhury
On Saturday 20 February 2010 11:46:42 Diez B. Roggisch wrote: > Am 20.02.10 17:12, schrieb lallous: > > Hello > > > > How can I do something similar to pure virtual functions in C++ ? > > > > Let us consider this: > > > > class C1: > > > > # Pure virtual > > def cb(self, param1, param2):

Re: Precision issue in python

2010-02-20 Thread Mark Dickinson
On Feb 20, 3:37 pm, mukesh tiwari wrote: > I don't know if is possible to import this decimal module but kindly > tell me.Also a bit about log implementation The decimal module is part of the standard library; I don't know what the rules are for SPOJ, but you're already importing the math module

Building a dict from a tuple of tuples

2010-02-20 Thread vsoler
Hello everyone! I have a tuple of tuples, coming from an Excel range, such as this: ((None, u'x', u'y'), (u'a', 1.0, 7.0), (u'b', None, 8.0)) I need to build a dictionary that has, as key, the row and column header. For example: d={ (u'a',u'x'):1.0, (u'a',u'y'): 7.0, (u'b',u'y'):8.0 } As you c

Re: Can't Access ANY url from python (errno 61)

2010-02-20 Thread Lie Ryan
On 02/20/10 19:36, MattB wrote: > On Feb 20, 2:02 am, Lie Ryan wrote: >> On 02/20/10 13:32, MattB wrote: >> >> >> >>> I'm using the network in my own apartment. Not the campus's. >>> Moreover, my mac's MAC address is different from the MAC address shown >>> by my router, but as I said I'm also blo

Re: the mystery of dirname()

2010-02-20 Thread MRAB
Shashwat Anand wrote: basically I infer that : dirname = path - basename, like for path = '//x', basename = x, hence dirname = '//' [snip] Basically, os.path.dirname() should return the directory name, which means dropping everything after the last slash, and also the last slash. However, the

Re: Precision issue in python

2010-02-20 Thread Mark Dickinson
On Sat, Feb 20, 2010 at 2:42 PM, Shashwat Anand wrote: > A quick solution I came out with, no stirling numbers and had tried to avoid > large integer multiplication as much as possible. > > import math > > for i in range(int(raw_input())): >     n, k, l = [int(i) for i in raw_input().split()] >   

Re: Building a dict from a tuple of tuples

2010-02-20 Thread MRAB
vsoler wrote: Hello everyone! I have a tuple of tuples, coming from an Excel range, such as this: ((None, u'x', u'y'), (u'a', 1.0, 7.0), (u'b', None, 8.0)) I need to build a dictionary that has, as key, the row and column header. For example: d={ (u'a',u'x'):1.0, (u'a',u'y'): 7.0, (u'b',u'y')

Re: Can't Access ANY url from python (errno 61)

2010-02-20 Thread Martin P. Hellwig
On 02/20/10 00:20, MattB wrote: Also, based on Martin's comment, I just wanted to make you all aware that I intend no misuse, but rather am just trying to learn, as I'm a programming noob. It wasn't my intention to imply that, rather the opposite, that if some BOFH would see your action as m

Re: the mystery of dirname()

2010-02-20 Thread Shashwat Anand
got it. thanks. :) On Sat, Feb 20, 2010 at 11:19 PM, MRAB wrote: > Shashwat Anand wrote: > >> basically I infer that : dirname = path - basename, like for path = >> '//x', basename = x, hence dirname = '//' >> >> [snip] > Basically, os.path.dirname() should return the directory name, which >

Re: Pure virtual functions in Python?

2010-02-20 Thread Peter Otten
lallous wrote: > How can I do something similar to pure virtual functions in C++ ? http://docs.python.org/library/abc.html#abc.abstractmethod Peter -- http://mail.python.org/mailman/listinfo/python-list

Re: Precision issue in python

2010-02-20 Thread Shashwat Anand
@Mark, The str(...).split('.') here doesn't do a good job of extracting the > integer part when its argument is >= 1e12, since Python produces a > result in scientific notation. I think you're going to get strange > results when k >= 13. > Yeah, you were correct. I tested it for k >= 13, and the

Compiling and running 32-bit Python on 64-bit server?

2010-02-20 Thread Mikko Ohtamaa
Hi, Some server-side Python applications are limited by memory usage (hint: Zope), because Python effective uses processes and not threads for multiprocessing. This is especially true for 64-bit platforms, since Python programs are all about references and objects and 64-bit effectively doubles re

Re: Building a dict from a tuple of tuples

2010-02-20 Thread vsoler
On Feb 20, 7:00 pm, MRAB wrote: > vsoler wrote: > > Hello everyone! > > > I have a tuple of tuples, coming from an Excel range, such as this: > > > ((None, u'x', u'y'), > > (u'a', 1.0, 7.0), > > (u'b', None, 8.0)) > > > I need to build a dictionary that has, as key, the row and column > > header.

Re: os.pipe() + os.fork()

2010-02-20 Thread Gary Herron
Sebastian Noack wrote: I have figured out that, you have to close the writing end in the child process, which is reading from the pipe. Otherwise the underlying pipe is not going to be closed when the parent process is closing its writing end. This has nothing to do with Python itself. I have tri

Re: Compiling and running 32-bit Python on 64-bit server?

2010-02-20 Thread Martin v. Loewis
> How one could create 32-bit Python run-time enviroment, preferable > virtualenv, on 64-bit Linux (VPS), reducing memory usage? I'd install a 32-bit Linux on the hardware, and install a bigmem kernel if it has more than 3GB of main memory. > I assume this involves having lib32 libs and compiling

if not global -- then what?

2010-02-20 Thread egasimus
Hi, newbie here. I've read on using the 'global' keyword being discouraged; then what is the preferred way to have something, for example a class containing program settings, accessible from everywhere, in a program spanning multiple files? -- http://mail.python.org/mailman/listinfo/python-list

Re: Building a dict from a tuple of tuples

2010-02-20 Thread MRAB
vsoler wrote: On Feb 20, 7:00 pm, MRAB wrote: vsoler wrote: Hello everyone! I have a tuple of tuples, coming from an Excel range, such as this: ((None, u'x', u'y'), (u'a', 1.0, 7.0), (u'b', None, 8.0)) I need to build a dictionary that has, as key, the row and column header. For example: d={ (

Re: if not global -- then what?

2010-02-20 Thread MRAB
egasimus wrote: Hi, newbie here. I've read on using the 'global' keyword being discouraged; then what is the preferred way to have something, for example a class containing program settings, accessible from everywhere, in a program spanning multiple files? Python's 'global' keyword is global in

Re: if not global -- then what?

2010-02-20 Thread Gary Herron
egasimus wrote: Hi, newbie here. I've read on using the 'global' keyword being discouraged; then what is the preferred way to have something, for example a class containing program settings, accessible from everywhere, in a program spanning multiple files? Define your "global" in a module (a

Re: if not global -- then what?

2010-02-20 Thread Krister Svanlund
On Sat, Feb 20, 2010 at 8:25 PM, egasimus wrote: > Hi, newbie here. I've read on using the 'global' keyword being > discouraged; then what is the preferred way to have something, for > example a class containing program settings, accessible from > everywhere, in a program spanning multiple files?

Re: Pure virtual functions in Python?

2010-02-20 Thread I V
On Sat, 20 Feb 2010 08:12:01 -0800, lallous wrote: > How can I do something similar to pure virtual functions in C++ ? >From what you want, it seems like you want cb() to not be called if it isn't implemented in the derived class; this isn't really what pure virtual functions in C++ do - pure vi

How would I do a continuous write over a pipe in the following code...

2010-02-20 Thread chad
Given the following #!/usr/bin/python import subprocess as s broadcast = s.Popen("echo test | wall", shell=True,stdout=s.PIPE) out = broadcast.stdout while 1: out broadcast.wait() broadcast.stdout.close() The code only executes once. What I want to do is be able to continuously w

Re: Building a dict from a tuple of tuples

2010-02-20 Thread vsoler
On Feb 20, 8:54 pm, MRAB wrote: > vsoler wrote: > > On Feb 20, 7:00 pm, MRAB wrote: > >> vsoler wrote: > >>> Hello everyone! > >>> I have a tuple of tuples, coming from an Excel range, such as this: > >>> ((None, u'x', u'y'), > >>> (u'a', 1.0, 7.0), > >>> (u'b', None, 8.0)) > >>> I need to build

Re: finding element by tag in xml

2010-02-20 Thread Jim
On Feb 20, 11:27 am, sWrath swrath wrote: > 2 Questions > > 1. Why can't I use dom.getElementsByTagName('book') in #Error 1? How > do i print the elements ? > Error- AttributeError: ElementTree instance has no attribute > 'getElementsByTagName' I only see one question here. I think the err

Re: finding element by tag in xml

2010-02-20 Thread Dj Gilcrease
On Sat, Feb 20, 2010 at 9:27 AM, sWrath swrath wrote: > from xml.dom.minidom import parse > from xml.etree.ElementTree import* > > file1="book.xml" > tmptree=ElementTree() > tmptree.parse(file1) > items=root.getiterator() > > > dom = parse(file1) > > > #Find tag names > for node in items : >    if

Re: Pure virtual functions in Python?

2010-02-20 Thread Arnaud Delobelle
lallous writes: > Hello > > How can I do something similar to pure virtual functions in C++ ? > > Let us consider this: > > class C1: > > # Pure virtual > def cb(self, param1, param2): > """ > This is a callback > > @param param1: ... > @param param2: ... >

Reading a large bz2 textfile exits early

2010-02-20 Thread Norman Rieß
Hello, i am trying to read a large bz2 compressed textfile using the bz2 module. The file is 1717362770 lines long and 8GB large. Using this code source_file = bz2.BZ2File(file, "r") for line in source_file: print line.strip() print "Exiting" print "I used file: " + file the loo

/usr/bin/ld: cannot find -lz on Cent OS - Python 2.4

2010-02-20 Thread V8 NUT
Been trying to fix this issue for over 6 hours now. It's doin my head in, any one know whats going on here. ==START== python setup.py build running build running build_py copying MySQLdb/release.py -> build/lib.linux-x86_64-2.4/MySQLdb running build_ext building '_mysql' extension gcc -pthread -sh

Re: calculating a string equation

2010-02-20 Thread Astan Chee
Arnaud Delobelle wrote: Astan Chee writes: Hi, I have some variables in my script that looks like this: vars = {'var_a':'10','var_b':'4'} eqat = "(var_a/2.0) <= var_b" result = "(var_a+var_b)/7" What I'm trying to do is to plug in var_a and var_b's values from vars into eqat and see if eqat

Re: calculating a string equation

2010-02-20 Thread Chris Rebert
On Sat, Feb 20, 2010 at 3:07 PM, Astan Chee wrote: > Arnaud Delobelle wrote: > Astan Chee writes: > Hi, > I have some variables in my script that looks like this: > vars = {'var_a':'10','var_b':'4'} > eqat = "(var_a/2.0) <= var_b" > result = "(var_a+var_b)/7" > What I'm trying to do is to plug in

Is there a way to continue after an exception ?

2010-02-20 Thread Stef Mientki
hello, I would like my program to continue on the next line after an uncaught exception, is that possible ? thanks Stef Mientki -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a way to continue after an exception ?

2010-02-20 Thread Krister Svanlund
On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki wrote: > hello, > > I would like my program to continue on the next line after an uncaught > exception, > is that possible ? > > thanks > Stef Mientki > Yes, you catch the exception and do nothing. -- http://mail.python.org/mailman/listinfo/python-l

Re: MODULE FOR I, P FRAME

2010-02-20 Thread Tim Roberts
DANNY wrote: > >If I want to have a MPEG-4/10 coded video and stream it through the >network and than have the same video on the client side, what should I >use and of course I don't want to have raw MPEG data, because than I >couldn't extract the frames to manipulate them. If you want to manipul

Re: if not global -- then what?

2010-02-20 Thread Steven D'Aprano
On Sat, 20 Feb 2010 11:25:46 -0800, egasimus wrote: > Hi, newbie here. I've read on using the 'global' keyword being > discouraged; then what is the preferred way to have something, for > example a class containing program settings, accessible from everywhere, > in a program spanning multiple file

Re: Can't Access ANY url from python (errno 61)

2010-02-20 Thread Steven D'Aprano
On Sat, 20 Feb 2010 18:28:16 +, Martin P. Hellwig wrote: > On 02/20/10 00:20, MattB wrote: > >> >> Also, based on Martin's comment, I just wanted to make you all aware >> that I intend no misuse, but rather am just trying to learn, as I'm a >> programming noob. > > It wasn't my intention to

Re: speed question, reading csv using takewhile() and dropwhile()

2010-02-20 Thread Vincent Davis
Thanks for the help, this is considerably faster and easier to read (see below). I changed it to avoid the "break" and I think it makes it easy to understand. I am checking the conditions each time slows it but it is worth it to me at this time. Thanks again Vincent def read_data_file(filename):

Re: Is there a way to continue after an exception ?

2010-02-20 Thread Lie Ryan
> On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki wrote: >> hello, >> >> I would like my program to continue on the next line after an uncaught >> exception, >> is that possible ? >> >> thanks >> Stef Mientki >> That reminds me of VB's "On Error Resume Next" -- http://mail.python.org/mailman/list

Re: The Disappearing Program?

2010-02-20 Thread rzed
"W. eWatson" wrote in news:hlls5c$89...@news.eternal-september.org: > I've successfully compiled several small python programs on Win > XP into executables using py2exe. A program goes from a name like > snowball.py to snowball. A dir in the command prompt window finds > snowball.py but not snow

Re: Is there a way to continue after an exception ?

2010-02-20 Thread Daniel Fetchinson
> I would like my program to continue on the next line after an uncaught > exception, > is that possible ? try: # here is your error except: pass # this will get executed no matter what See http://docs.python.org/tutorial/errors.html HTH, Daniel -- Psss, psss, put it down! - http://

Re: The future of "frozen" types as the number of CPU cores increases

2010-02-20 Thread Tim Roberts
Chris Rebert wrote: >On Thu, Feb 18, 2010 at 11:58 AM, John Nagle wrote: >> >>   Python isn't ready for this.  Not with the GIL. > >Is any language, save perhaps Erlang, really ready for it? F# is. I only wish the syntax was a little less Perl-like. Too many special characters. -- Tim Robert

Re: The Disappearing Program?

2010-02-20 Thread MRAB
rzed wrote: "W. eWatson" wrote in news:hlls5c$89...@news.eternal-september.org: I've successfully compiled several small python programs on Win XP into executables using py2exe. A program goes from a name like snowball.py to snowball. A dir in the command prompt window finds snowball.py but n

Efficient way to break up a list into two pieces

2010-02-20 Thread marwie
Hello, I recently read about augmented assignments and that (with l1, l2 being lists) l1.extend(l2) is more efficient than l1 = l1 + l2 because unnecessary copy operations can be avoided. Now my question is if there's a similar thing for breaking a list into two parts. Let's say I want

Not sure why this is filling my sys memory

2010-02-20 Thread Vincent Davis
Code is below, The files are about 5mb and 230,000 rows. When I have 43 files of them and when I get to the 35th (reading it in) my system gets so slow that it is nearly functionless. I am on a mac and activity monitor shows that python is using 2.99GB of memory (of 4GB). (python 2.6 64bit). The ge

Re: Efficient way to break up a list into two pieces

2010-02-20 Thread Jonathan Gardner
On Sat, Feb 20, 2010 at 4:55 PM, marwie wrote: > Hello, > > I recently read about augmented assignments and that (with l1, l2 > being lists) > >    l1.extend(l2) > > is more efficient than > >    l1 = l1 + l2 > > because unnecessary copy operations can be avoided. Now my question is > if there's a

Re: Not sure why this is filling my sys memory

2010-02-20 Thread Vincent Davis
> Code is below, The files are about 5mb and 230,000 rows. When I have 43 > files of them and when I get to the 35th (reading it in) my system gets so > slow that it is nearly functionless. I am on a mac and activity monitor > shows that python is using 2.99GB of memory (of 4GB). (python 2.6 64bit)

Re: Efficient way to break up a list into two pieces

2010-02-20 Thread Shashwat Anand
You can always implement your own data-structures or simply a function if you need so. A language consist of building blocks and not buildings. On Sun, Feb 21, 2010 at 6:36 AM, Jonathan Gardner < jgard...@jonathangardner.net> wrote: > On Sat, Feb 20, 2010 at 4:55 PM, marwie wrote: > > Hello, > >

Re: speed question, reading csv using takewhile() and dropwhile()

2010-02-20 Thread Jonathan Gardner
On Sat, Feb 20, 2010 at 4:21 PM, Vincent Davis wrote: > Thanks for the help, this is considerably faster and easier to read (see > below). I changed it to avoid the "break" and I think it makes it easy to > understand. I am checking the conditions each time slows it but it is worth > it to me at t

Re: speed question, reading csv using takewhile() and dropwhile()

2010-02-20 Thread Vincent Davis
Thanks again for the comment, not sure I will implement all of it but I will separate the "if not row" The files have some extraneous blank rows in the middle that I need to be sure not to import as blank rows. I am actually having trouble with this filling my sys memory, I posted a separate questi

Re: if not global -- then what?

2010-02-20 Thread Jonathan Gardner
On Sat, Feb 20, 2010 at 11:25 AM, egasimus wrote: > Hi, newbie here. I've read on using the 'global' keyword being > discouraged; then what is the preferred way to have something, for > example a class containing program settings, accessible from > everywhere, in a program spanning multiple files?

Re: Efficient way to break up a list into two pieces

2010-02-20 Thread Steven D'Aprano
On Sat, 20 Feb 2010 16:55:10 -0800, marwie wrote: > Hello, > > I recently read about augmented assignments and that (with l1, l2 being > lists) > > l1.extend(l2) > > is more efficient than > > l1 = l1 + l2 > > because unnecessary copy operations can be avoided. Now my question is > if

Re: /usr/bin/ld: cannot find -lz on Cent OS - Python 2.4

2010-02-20 Thread Jonathan Gardner
On Sat, Feb 20, 2010 at 3:03 PM, V8 NUT wrote: > /usr/bin/ld: skipping incompatible /usr/lib/libz.so when searching for > -lz > /usr/bin/ld: skipping incompatible /usr/lib/libz.a when searching for - > lz > /usr/bin/ld: cannot find -lz This is your problem. > > Am trying to get MySQL-python-1.

Re: datelib pythonification

2010-02-20 Thread alex goretoy
hello all, since I posted this last time, I've added a new function dates_diff and modified the dates_dict function to set timedelta values returned by dates_diff in the returned dict def dates_dict(self,*targs,**dargs): """ dates_dict() - takes params same as prefs()

Re: speed question, reading csv using takewhile() and dropwhile()

2010-02-20 Thread Jonathan Gardner
On Sat, Feb 20, 2010 at 5:32 PM, Vincent Davis wrote: > > Thanks again for the comment, not sure I will implement all of it but I will > separate the "if not row" The files have some extraneous blank rows in the > middle that I need to be sure not to import as blank rows. > I am actually having

Re: Not sure why this is filling my sys memory

2010-02-20 Thread Jonathan Gardner
On Sat, Feb 20, 2010 at 5:07 PM, Vincent Davis wrote: >> Code is below, The files are about 5mb and 230,000 rows. When I have 43 >> files of them and when I get to the 35th (reading it in) my system gets so >> slow that it is nearly functionless. I am on a mac and activity monitor >> shows that py

Re: Efficient way to break up a list into two pieces

2010-02-20 Thread Steven D'Aprano
On Sat, 20 Feb 2010 17:06:36 -0800, Jonathan Gardner wrote: > On Sat, Feb 20, 2010 at 4:55 PM, marwie wrote: [...] >>    l2 = l1[10:] >>    del l1[10:] >> >> But since I'm assigning a slice the elements will be copied. Basically, >> I'm looking for something like l1.pop(10,len(l1)) which returns

netcdf4-python

2010-02-20 Thread deadpickle
I'm trying to use the python module "netcdf4-python" to read a netcdf file. So far I'm trying to do the basics and just open the script: from netCDF4 import Dataset rootgrp = Dataset('20060402-201025.netcdf', 'r', format='NETCDF3_CLASSIC') print rootgrp.file_format rootgrp.close() when I do this

Re: Not sure why this is filling my sys memory

2010-02-20 Thread Vincent Davis
On Sat, Feb 20, 2010 at 6:44 PM, Jonathan Gardner < > jgard...@jonathangardner.net> wrote: With this kind of data set, you should start looking at BDBs or PostgreSQL to hold your data. While processing files this large is possible, it isn't easy. Your time is better spent letting the DB figure

Re: if not global -- then what?

2010-02-20 Thread Steven D'Aprano
On Sat, 20 Feb 2010 17:34:15 -0800, Jonathan Gardner wrote: > In terms of "global", you should only really use "global" when you are > need to assign to a lexically scoped variable that is shared among other > functions. For instance: > > def foo(): > i = 0 > def inc(): global i; i+=1 >

Re: Efficient way to break up a list into two pieces

2010-02-20 Thread marwie
On 21 Feb., 02:30, Steven D'Aprano wrote: > Python lists are arrays of pointers to objects, so copying a slice is > fast: it doesn't have to copy the objects, just pointers. Deleting from > the end of the list is also quick, because you don't have to move memory, > just clear some pointers and cha

Re: The future of "frozen" types as the number of CPU cores increases

2010-02-20 Thread sjdevn...@yahoo.com
On Feb 18, 2:58 pm, John Nagle wrote: >     Multiple processes are not the answer.  That means loading multiple > copies of the same code into different areas of memory.  The cache > miss rate goes up accordingly. A decent OS will use copy-on-write with forked processes, which should carry throug

Re: Is there a way to continue after an exception ?

2010-02-20 Thread Lie Ryan
On 02/21/10 12:02, Stef Mientki wrote: > On 21-02-2010 01:21, Lie Ryan wrote: >>> On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki wrote: >>> hello, I would like my program to continue on the next line after an uncaught exception, is that possible ? thanks Ste

Re: Is there a way to continue after an exception ?

2010-02-20 Thread sstein...@gmail.com
On Feb 20, 2010, at 9:17 PM, Lie Ryan wrote: > On 02/21/10 12:02, Stef Mientki wrote: >> On 21-02-2010 01:21, Lie Ryan wrote: On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki > wrote: > hello, > > I would like my program to continue on the next line after an uncaught >

Re: The future of "frozen" types as the number of CPU cores increases

2010-02-20 Thread John Nagle
sjdevn...@yahoo.com wrote: On Feb 18, 2:58 pm, John Nagle wrote: Multiple processes are not the answer. That means loading multiple copies of the same code into different areas of memory. The cache miss rate goes up accordingly. A decent OS will use copy-on-write with forked processes,

Re: Is there a way to continue after an exception ?

2010-02-20 Thread Ryan Kelly
On Sun, 2010-02-21 at 13:17 +1100, Lie Ryan wrote: > On 02/21/10 12:02, Stef Mientki wrote: > > On 21-02-2010 01:21, Lie Ryan wrote: > >>> On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki > wrote: > >>> > hello, > > I would like my program to continue on the next line after an uncaugh

Re: Efficient way to break up a list into two pieces

2010-02-20 Thread marwie
On 21 Feb., 02:41, Steven D'Aprano wrote: > What the OP is doing is quite different: > > (1) copy l1[:10] > (2) assign the name l2 to it > (3) resize l1 in place to the first 10 items. > > What the OP wants is: > > (1) assign the name l2 to l1[:10] without copying > (2) resize l1 in place to the f

Re: Not sure why this is filling my sys memory

2010-02-20 Thread Vincent Davis
Here is a sample of the output, It almost instantly uses 2GB and then starts using VMem. This is probably the right suggestion but it's another thing to install > It's probably also worth being aware of guppy's heapy stuff: http://guppy-pe.sourceforge.net/heapy_tutorial

Re: netcdf4-python

2010-02-20 Thread Matt Newville
On Feb 20, 7:47 pm, deadpickle wrote: > I'm trying to use the python module "netcdf4-python" to read a netcdf > file. So far I'm trying to do the basics and just open the script: > > from netCDF4 import Dataset > rootgrp = Dataset('20060402-201025.netcdf', 'r', > format='NETCDF3_CLASSIC') > print

lists of variables

2010-02-20 Thread Michael Pardee
I'm relatively new to python and I was very surprised by the following behavior: >>> a=1 >>> b=2 >>> mylist=[a,b] >>> print mylist [1, 2] >>> a=3 >>> print mylist [1, 2] Whoah! Are python lists only for literals? Nope: >>> c={} >>> d={} >>> mydlist=[c,d] >>> print mydlist [{}, {}] >>> c['x']=1

Re: lists of variables

2010-02-20 Thread Chris Rebert
On Sat, Feb 20, 2010 at 7:25 PM, Michael Pardee wrote: > I'm relatively new to python and I was very surprised by the following > behavior: > a=1 b=2 mylist=[a,b] print mylist > [1, 2] a=3 print mylist > [1, 2] > > Whoah!  Are python lists only for literals?  Nope: >

Re: Efficient way to break up a list into two pieces

2010-02-20 Thread Steven D'Aprano
On Sat, 20 Feb 2010 17:55:18 -0800, marwie wrote: > On 21 Feb., 02:30, Steven D'Aprano cybersource.com.au> wrote: >> Python lists are arrays of pointers to objects, so copying a slice is >> fast: it doesn't have to copy the objects, just pointers. Deleting from >> the end of the list is also quic

Re: lists of variables

2010-02-20 Thread Stephen Hansen
On Sat, Feb 20, 2010 at 7:25 PM, Michael Pardee wrote: > But what would be "the python way" to accomplish "list of variables" > functionality? > The problem is... Python doesn't have variables. At least not in the way that you may be used to from other languages. Yeah, it's got data, and data obv

Re: The future of "frozen" types as the number of CPU cores increases

2010-02-20 Thread Paul Rubin
John Nagle writes: >> A decent OS will use copy-on-write with forked processes, which should >> carry through to the cache for the code. > >That doesn't help much if you're using the subprocess module. The > C code of the interpreter is shared, but all the code generated from > Python is not.

Re: lists of variables

2010-02-20 Thread Ben Finney
Michael Pardee writes: > But what would be "the python way" to accomplish "list of variables" > functionality? You'll need to explain what “list of variables” functionality is. If you mean “collection of name-to-value mappings”, the native mapping type in Python is ‘dict’. If that doesn't meet

  1   2   >