Re: best way to compare contents of 2 lists?

2009-04-27 Thread ajaksu
On Apr 24, 4:41 pm, norseman  wrote:
> (How do I) ...explain these?
[...]
> I can get the sashimi and take it home and BBQ it, I can roast it, I can
> steam it, I can wok it,..., but the other is what it is. (greasy)
>
> Besides, who says I like your cooking?  :)

Err... http://mail.python.org/pipermail/python-list/2008-September/679360.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Supply a plugin interface

2009-04-27 Thread Johannes Bauer
Steven D'Aprano schrieb:

>> How do I do that at runtime with Python?
> 
> Untested:
[Code]
> Hope this is useful.

Very, very, very useful. Works like a charm, just like that. Thanks a
whole bunch!

Kind regards,
Johannes

-- 
"Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verlästerung von Gott, Bibel und mir und bewusster Blasphemie."
 -- Prophet und Visionär Hans Joss aka HJP in de.sci.physik
 <48d8bf1d$0$7510$54022...@news.sunrise.ch>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Get item from set

2009-04-27 Thread Johannes Bauer
Johannes Bauer schrieb:

> Is there something like the "getelement" function? How can I do what I want?

One side note: The obvious trivial solution:

def findset(s, e):
for i in s:
if e == i:
return i
return None

is because of its complexity of O(n) against the native O(log n) out of
the question...

Kind regards,
Johannes

-- 
"Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verlästerung von Gott, Bibel und mir und bewusster Blasphemie."
 -- Prophet und Visionär Hans Joss aka HJP in de.sci.physik
 <48d8bf1d$0$7510$54022...@news.sunrise.ch>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Get item from set

2009-04-27 Thread Johannes Bauer
Peter Otten schrieb:

> class Grab:
> def __init__(self, value):
> self.search_value = value
> def __hash__(self):
> return hash(self.search_value)
> def __eq__(self, other):
> if self.search_value == other:
> self.actual_value = other
> return True
> return False
> 
> assert a == z
> assert a is not z
> grab = Grab(z)
> grab in s
> assert grab.actual_value is a

Wow, this is truly amazing! I'd never have come up with that solution.
Just wonderful, thank you very much! :-))

Kind regards,
Johannes

-- 
"Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verlästerung von Gott, Bibel und mir und bewusster Blasphemie."
 -- Prophet und Visionär Hans Joss aka HJP in de.sci.physik
 <48d8bf1d$0$7510$54022...@news.sunrise.ch>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Re: ActiveState Komodo Edit?

2009-04-27 Thread John Doe
Dave Angel  wrote:

...

> Quickest way to indent multiple lines is to select them, then
> press tab.  

Thanks.
Useful because I usually paste blocks of code.

Lastly... Is there a way to force the editor to open text (*.txt)
files as Python files so that they are color-coded? Without changing
the *.txt extension? I will be editing text files that are part of a
Python program (Dragonfly). Having the text color-coded will help. I
can probably make a script to do a workaround, but being able to
just hit the Save button would be best. 

Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: getting linux distro used...

2009-04-27 Thread James Matthews
You can always pipe the information for the command line.

On Mon, Apr 27, 2009 at 8:59 AM, David Lyon wrote:

>
> perphaps platform.uname()?
>
> On Sun, 26 Apr 2009 22:35:29 -0700 (PDT), deostroll 
> wrote:
> > Hi,
> >
> > I just found that you could use platform.system() to get the
> > underlying os used. But is there a way to get the distro used...?
> >
> > --deostroll
> > --
> > http://mail.python.org/mailman/listinfo/python-list
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 

http://www.astorandblack.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: getting linux distro used...

2009-04-27 Thread Lawrence D'Oliveiro
In message , deostroll wrote:

> I just found that you could use platform.system() to get the
> underlying os used. But is there a way to get the distro used...?

Mostly the differences will not be important. But if you want to know, I 
have been compiling a list of tests here 
.

--
http://mail.python.org/mailman/listinfo/python-list


Re: mailbox.mbox.add() also seems to set file permissions

2009-04-27 Thread tinnews
Aahz  wrote:
> In article ,
> Grant Edwards   wrote:
> >On 2009-04-25, tinn...@isbd.co.uk  wrote:
> >>
> >> Where should one report bugs/errors in python library classes?
> >
> >http://docs.python.org/bugs.html
> 
> That's for doc bugs; regular bugs go to bugs.python.org (which is
> currently down due to hardware problems).

No, it's a page that tells you how to report bugs, it directs you to
bugs.python.org which, as you say, is dead at the moment.

-- 
Chris Green

--
http://mail.python.org/mailman/listinfo/python-list


Re: getting linux distro used...

2009-04-27 Thread r-w

deostroll wrote:

Hi,

I just found that you could use platform.system() to get the
underlying os used. But is there a way to get the distro used...?

--deostroll


platform.dist() returns
('debian', 'lenny/sid', '')
on my Ubuntu box.

Ross
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a maximum size to a Python program?

2009-04-27 Thread Lawrence D'Oliveiro
In message , Paul Hemans wrote:

> One problem though that I didn't mention in my original
> posting was that the replication may only require updating one or more
> fields, that is a problem with a generating a single SQL statement to
> cover all requests.

That's not a big issue. Assume the field names and corresponding values are 
coming from a Python dict, eg

FieldValues = \
  {
"field1" : ... value1 ...;
"field2" : ... value2 ...;
 }

then you can construct an SQL statement on the fly with something like

sqlcmd = \
(
"insert into my_table set "
+
", ".join
  (
"%s = %s" % (k, SQLString(FieldValues[k]))
for k in FieldValues.keys()
  )
)

where SQLString is as defined at 
.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Into itertools

2009-04-27 Thread Arnaud Delobelle
On 26 Apr, 17:32, bearophileh...@lycos.com wrote:
> Some idioms are so common that I think they deserve to be written in C
> into the itertools module.
>
> 1) leniter(iterator)
[...]
> A Python implementation:
>
> def leniter(iterator):
>     if hasattr(iterator, "__len__"):
>         return len(iterator)
>     nelements = 0
>     for _ in iterator:
>         nelements += 1
>     return nelements

Some people would write it as:

def leniter(iterable):
if hasattr(iterable, '__len__'):
return len(iteratble)
return sum(1 for _ in iterable)

[...]

> 2) xpairwise(iterable)
>
> This is at the the bottom of the itertools docs:
>
> def pairwise(iterable):
>     a, b = tee(iterable)
>     for elem in b:
>         break
>     return izip(a, b)
>
> The following of mine is faster:
>
> def xpairwise(iterable):
>     return izip(iterable, islice(iterable, 1, None))

This doesn't work if the iterable is an iterator.

E.g

>>> it = iter(range(5))
>>> list(xpairwise(it))
[(0, 2), (3, 4)]

[...]
> 3) xpairs(seq)
>
> This is a Python implementation:
>
> def xpairs(seq):
>     len_seq = len(seq)
>     for i, e1 in enumerate(seq):
>         for j in xrange(i+1, len_seq):
>             yield e1, seq[j]
>

Why not:

def xpairs(seq):
for i, el in enumerate(seq):
for j in xrange(i):
yield seq[j], el


--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list


Re: Into itertools

2009-04-27 Thread bearophileHUGS
Arnaud Delobelle:

> Some people would write it as:
>
> def leniter(iterable):
>     if hasattr(iterable, '__len__'):
>         return len(iteratble)
>     return sum(1 for _ in iterable)

That's slower than my version.



> > def xpairwise(iterable):
> >     return izip(iterable, islice(iterable, 1, None))
>
> This doesn't work if the iterable is an iterator.

I see. I think I have never used it with an iterator so far :-)
I'll fix it.


> Why not:
>
> def xpairs(seq):
>     for i, el in enumerate(seq):
>         for j in xrange(i):
>             yield seq[j], el

Maybe because I was not smart enough to invent that :-)

---

Mark Dickinson:

> 3) xpairs(seq)
> >>> list(xpairs(range(5)))
> [(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4), (2, 3),
> (2, 4), (3, 4)]

Doesn't itertools.combinations already do this for you?
>>> list(itertools.combinations(range(5), 2))

I have written most of those functions when I have used Python 2.4,
before itertools.combinations. But you are right, xpairs is now almost
useless, just one line long :-) Combinatorics is so fun :-)

Thank you very much to both.

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: Into itertools

2009-04-27 Thread Mark Dickinson
On Apr 26, 5:32 pm, bearophileh...@lycos.com wrote:

> 3) xpairs(seq)

>     >>> list(xpairs(range(5)))
>     [(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4), (2, 3),
> (2, 4), (3, 4)]

Doesn't itertools.combinations already do this for you?

>>> list(itertools.combinations(range(5), 2))
[(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4), (2, 3), (2,
4), (3, 4)]

Mark
--
http://mail.python.org/mailman/listinfo/python-list


Re: Thread-killing, round 666 (was Re: Lisp mentality vs. Python mentality)

2009-04-27 Thread Vsevolod
On Apr 27, 3:20 am, a...@pythoncraft.com (Aahz) wrote:
> In article 
> <793a5176-ec2d-4ffd-b1e7-762077733...@v35g2000pro.googlegroups.com>,
>
> Vsevolod   wrote:
> >On Apr 26, 6:28 pm, a...@pythoncraft.com (Aahz) wrote:
>
> >> The problem is that thread-killing (in the literal sense) doesn't work.
> >> Unlike processes, there's no thread-environment encapsulation at the OS
> >> level, which means that things don't get cleaned up properly.  Even Java
> >> has mostly given up on thread-killing.  The only way to kill threads
> >> safely is to have them terminate themselves.  Your other option is to use
> >> multiple processes.
>
> >Well, somehow, in Lisp it's not a problem. :)
>
> Does Lisp even have OS-level threads?  What Lisp are you using, on what
> OS?  Are they perhaps Erlang-style cooperative threads instead?
> --
> Aahz (a...@pythoncraft.com)   <*>http://www.pythoncraft.com/
>
> "If you think it's expensive to hire a professional to do the job, wait
> until you hire an amateur."  --Red Adair

Different Lisp implementations provide different solutions. SBCL
provides OS-level threads (on Linux), which I personally use, while
CMUCL offers green threads. Allegro, LispWorks, Clozure CL, Sceineer
CL and ECL as well have threading, but I don't use them, so won't
speak, which implementation of threading they have. There's a common
unification library -- bordeaux-threads -- that abstracts away
implementation specifics. It's API includes the function destroy-
thread.

As well I'd like to outline, that, IMO, your answer exhibits the
common attitude among pythonistas: everything should be done in one
true way, which is the best option (and that is how it's implemented
in the current version of the language). As of PEP-20: "There should
be one-- and preferably only one --obvious way to do it. Although that
way may not be obvious at first unless you're Dutch." And if someone
disagrees -- he just doesn't understand...

Cheers,
Vsevolod
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a maximum size to a Python program?

2009-04-27 Thread Duncan Booth
Lawrence D'Oliveiro  wrote:

> In message , Paul Hemans wrote:
> 
>> One problem though that I didn't mention in my original
>> posting was that the replication may only require updating one or
>> more fields, that is a problem with a generating a single SQL
>> statement to cover all requests.
> 
> That's not a big issue. Assume the field names and corresponding
> values are coming from a Python dict, eg
> 
> FieldValues = \
>   {
> "field1" : ... value1 ...;
> "field2" : ... value2 ...;
>  }
> 
> then you can construct an SQL statement on the fly with something like
> 
> sqlcmd = \
> (
> "insert into my_table set "
> +
> ", ".join
>   (
> "%s = %s" % (k, SQLString(FieldValues[k]))
> for k in FieldValues.keys()
>   )
> )
> 
> where SQLString is as defined at 
>>. 
> 
> 

Not so nice if the input data is something like:

FieldValues = { "field1=0);DROP my_table;": "" }

So you want something to validate fieldnames.

Also you are assuming that all the values are strings: if you want to 
handle different data types correctly it is probably simpler to insert 
parameter placeholders in the dynamic sql statement and just pass 
FieldValues.items() to the execute method.

-- 
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: getting linux distro used...

2009-04-27 Thread Sebastian Wiesner


> In message  a88b-2ded6f8af...@y33g2000prg.googlegroups.com>, deostroll wrote:
> 
>> I just found that you could use platform.system() to get the
>> underlying os used. But is there a way to get the distro used...?
> 
> Mostly the differences will not be important. But if you want to know, I
> have been compiling a list of tests here
> 
.

At least the Gentoo-Test is not very reliable.  While "/usr/portage/" is the 
default location for the portage tree, it is not enforced, neither by 
portage nor by alternative package managers like paludis.  The portage tree 
as well as the distfiles can perfectly moved to another directory (I've done 
so).

Testing for the existing of "/usr/bin/emerge" or even better "/etc/gentoo-
release" seems more reliable to me.  The latter is also used by Python to 
implement "platform.dist()".

-- 
Freedom is always the freedom of dissenters.
  (Rosa Luxemburg)

--
http://mail.python.org/mailman/listinfo/python-list


Re: ActiveState Komodo Edit?

2009-04-27 Thread Dave Angel

John Doe wrote:

Dave Angel  wrote:

...

  

Quickest way to indent multiple lines is to select them, then
press tab.  



Thanks.
Useful because I usually paste blocks of code.

Lastly... Is there a way to force the editor to open text (*.txt)
files as Python files so that they are color-coded? Without changing
the *.txt extension? I will be editing text files that are part of a
Python program (Dragonfly). Having the text color-coded will help. I
can probably make a script to do a workaround, but being able to
just hit the Save button would be best. 


Thanks.

  
I haven't tried it in Komodo IDE, but there is a preferences item called 
File Associations.  In it, try choosing *.txt, and change the language 
drop-down to Python.  Presumably when you're done with the special case, 
you'd change it back to "text file"




--
http://mail.python.org/mailman/listinfo/python-list


Re: getting linux distro used...

2009-04-27 Thread Lawrence D'Oliveiro
In message , Sebastian Wiesner wrote:

> 
> 
>> .
> 
> At least the Gentoo-Test is not very reliable.

It's a wiki. You know what to do.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a maximum size to a Python program?

2009-04-27 Thread Lawrence D'Oliveiro
In message , Duncan Booth wrote:

> Lawrence D'Oliveiro  wrote:
> 
>> In message , Paul Hemans wrote:
>> 
>>> One problem though that I didn't mention in my original
>>> posting was that the replication may only require updating one or
>>> more fields, that is a problem with a generating a single SQL
>>> statement to cover all requests.
>> 
>> That's not a big issue. Assume the field names and corresponding
>> values are coming from a Python dict, eg
>> 
>> FieldValues = \
>>   {
>> "field1" : ... value1 ...;
>> "field2" : ... value2 ...;
>>  }
>> 
>> then you can construct an SQL statement on the fly with something like
>> 
>> sqlcmd = \
>> (
>> "insert into my_table set "
>> +
>> ", ".join
>>   (
>> "%s = %s" % (k, SQLString(FieldValues[k]))
>> for k in FieldValues.keys()
>>   )
>> )
>> 
>> where SQLString is as defined at
>> title=Useful_MySQL_Routines#Quoting
>>>.
>> 
>> 
> 
> Not so nice if the input data is something like:
> 
> FieldValues = { "field1=0);DROP my_table;": "" }
> 
> So you want something to validate fieldnames.

That's not going to happen. These are field names, not values you're talking 
about.

> Also you are assuming that all the values are strings ...

No I'm not.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Thread-killing, round 666 (was Re: Lisp mentality vs. Python mentality)

2009-04-27 Thread Richard Brodie

"Vsevolod"  wrote in message 
news:42cebb2b-0361-416c-8932-9371da50a...@y6g2000prf.googlegroups.com...

> There's a common unification library -- bordeaux-threads -- 
> that abstracts away implementation specifics. It's API includes
> the function destroy-thread.

Which is deprecated, like the Java one. It's not hard to provide
a kill thread call, if you don't mind it having undefined semantics. 


--
http://mail.python.org/mailman/listinfo/python-list


Re: getting linux distro used...

2009-04-27 Thread Marcin Stępnicki
Dnia Sun, 26 Apr 2009 22:35:29 -0700, deostroll napisał(a):

> Hi,
> 
> I just found that you could use platform.system() to get the underlying
> os used. But is there a way to get the distro used...?

Perhaps reading /etc/issue is sufficient? However, I know that for 
example Slackware puts its version in /etc/slackware-version :>. 
--
http://mail.python.org/mailman/listinfo/python-list


CSV performance

2009-04-27 Thread psaff...@googlemail.com
I'm using the CSV library to process a large amount of data - 28
files, each of 130MB. Just reading in the data from one file and
filing it into very simple data structures (numpy arrays and a
cstringio) takes around 10 seconds. If I just slurp one file into a
string, it only takes about a second, so I/O is not the bottleneck. Is
it really taking 9 seconds just to split the lines and set the
variables?

Is there some way I can improve the CSV performance? Is there a way I
can slurp the file into memory and read it like a file from there?

Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: ActiveState Komodo Edit?

2009-04-27 Thread John Doe
Dave Angel  wrote: 
> John Doe wrote: 
>> Dave Angel  wrote: 

... 

>> Lastly... Is there a way to force the editor to open text (*.txt)
>> files as Python files so that they are color-coded? Without 
>> changing the *.txt extension? I will be editing text files that 
>> are part of a Python program (Dragonfly). Having the text 
>> color-coded will help. I can probably make a script to do a 
>> workaround, but being able to just hit the Save button would be 
>> best. 

> I haven't tried it in Komodo IDE, but there is a preferences item 
> called File Associations.  In it, try choosing *.txt, and change 
> the language drop-down to Python.  

Did that. 

> Presumably when you're done with the special case, you'd change it
> back to "text file" 

Apparently works great (except for some strange GUI behavior in that
dialogue, but that is a completely different, minor issue). For some
reason, seems Komodo does not allow itself to be configured from
Windows file types to open text files, but that is not necessary or
even desirable here. I will just have it open the last files being
worked on. Apparently the editor behaves the same way as it did for
Python files. Thanks. 
--
http://mail.python.org/mailman/listinfo/python-list


Dynamically fill prepared (PDF?) forms

2009-04-27 Thread pom

Hello

I'm looking for a way to fill in forms with data retrieved from a mysql 
db.  But what I'm especially looking for is an easy way to create the 
layout of the forms itself.


Handling data from mysql is not a problem for me.  Making static 
programmed PDF output using Reportlab is not a problem.  But I want to 
give the user the possibility to change the layout of the outputted PDF 
without making changes to my source code.


So I want to create PDF output based on an external layout file.

I'll hope you understand what I want to achieve...
(and sorry for my bad english)


Greetings!



Pom
--
http://mail.python.org/mailman/listinfo/python-list


Re: Thread-killing, round 666 (was Re: Lisp mentality vs. Python mentality)

2009-04-27 Thread Francesco Guerrieri
On Mon, Apr 27, 2009 at 11:55 AM, Vsevolod  wrote:

>
> As well I'd like to outline, that, IMO, your answer exhibits the
> common attitude among pythonistas: everything should be done in one
> true way, which is the best option (and that is how it's implemented
> in the current version of the language). As of PEP-20: "There should
> be one-- and preferably only one --obvious way to do it. Although that
> way may not be obvious at first unless you're Dutch." And if someone
> disagrees -- he just doesn't understand...
>
> Cheers,
> Vsevolod
>


Well, I'd rather say that if someone disagrees, she is free to use Lisp :-)
What I like about Python (my own idea of Pythonicity) is that it is similar
to Unix: Python has a phylosophy.
Guido's ideas, and of all the author and contributors to the PEPs, have till
now shaped a language.
What cannot be added to it in an elegant way, consistent with the overall
picture,
is better kept out of the language. It's not a matter of attitude or
understanding...

Francesco
--
http://mail.python.org/mailman/listinfo/python-list


Re: Thread-killing, round 666 (was Re: Lisp mentality vs. Python mentality)

2009-04-27 Thread Vsevolod
On Apr 27, 2:17 pm, "Richard Brodie"  wrote:
> "Vsevolod"  wrote in message
>
> news:42cebb2b-0361-416c-8932-9371da50a...@y6g2000prf.googlegroups.com...
>
> > There's a common unification library -- bordeaux-threads --
> > that abstracts away implementation specifics. It's API includes
> > the function destroy-thread.
>
> Which is deprecated, like the Java one. It's not hard to provide
> a kill thread call, if you don't mind it having undefined semantics.

"This should be used with caution: it is implementation-defined
whether the thread runs cleanup forms or releases its locks first."
This doesn't mean deprecated. It means: implementation-dependent. For
example in SBCL: "Terminate the thread identified by thread, by
causing it to run sb-ext:quit - the usual cleanup forms will be
evaluated". And it works fine.

Best regards,
Vsevolod
--
http://mail.python.org/mailman/listinfo/python-list


Web based application development using python

2009-04-27 Thread Rahul
Hello all,

I have two questions
1)  When will be python3.1 (final) get released? (The date should be
appropriate (proposed), it must be the span in between which there are
chances of release)
2)  I have my web based application written using mod_python but was
needed to know if there is better option other than mod_python to
develop web based applications in python which can be easy to maintain
and debug?
a.  It should be more based on framework type.
b.  It should have all the features present in mod_python.
c.  Client-server driven architecture support.

Any help regarding will be greatly appreciated.


Thanks & Regards,

Rahul Warhekar
--
http://mail.python.org/mailman/listinfo/python-list


is PyCodec_Encode API able to change encoding fron UCS-2 to UCS-4

2009-04-27 Thread rahul

is this generic API can be use to change ucs-2 to ucs-4
PyObject *  PyCodec_Encode(
   PyObject *object,
   const char *encoding,
   const char *errors
   );

if yes than what is the format of denoting ucs-4, because i try to do
that but all times i got segmentation fault, i used "ucs-4-le" for
little endian system and "ucs-4-be"  for big endian system to set
ucs-4 encoding.
--
http://mail.python.org/mailman/listinfo/python-list


is PyCodec_Encode API able to change encoding fron UCS-2 to UCS-4

2009-04-27 Thread rahul

is this generic API can be use to change ucs-2 to ucs-4
PyObject *  PyCodec_Encode(
   PyObject *object,
   const char *encoding,
   const char *errors
   );

if yes than what is the format of denoting ucs-4, because i try to do
that but all times i got segmentation fault, i used "ucs-4-le" for
little endian system and "ucs-4-be"  for big endian system to set
ucs-4 encoding.

-
Rahul Priyadarshi
--
http://mail.python.org/mailman/listinfo/python-list


Re: CSV performance

2009-04-27 Thread John Machin
On Apr 27, 9:22 pm, "psaff...@googlemail.com"
 wrote:
> I'm using the CSV library to process a large amount of data - 28
> files, each of 130MB. Just reading in the data from one file and
> filing it into very simple data structures (numpy arrays and a
> cstringio) takes around 10 seconds. If I just slurp one file into a
> string, it only takes about a second, so I/O is not the bottleneck. Is
> it really taking 9 seconds just to split the lines and set the
> variables?

I'll assume that that's a rhetorical question. Why are you assuming
that it's a problem with the csv module and not with the "filing it
into very simple data structures"? How long does it take just to read
the CSV file i.e. without any setting the variables? Have you run your
timing tests multiple times and discarded the first 1 or two results?

> Is there some way I can improve the CSV performance?

I doubt it.

> Is there a way I
> can slurp the file into memory and read it like a file from there?

Of course. However why do you think that the double handling will be
faster? Do you have 130MB of real memory free for the file image?

In order to get some meaningful advice, you will need to tell us:
version of Python, version of numpy, OS, amount of memory on the
machine, what CPU; and supply: sample of a few lines of a typical CSV
file, plus your code.

Cheers,
John
--
http://mail.python.org/mailman/listinfo/python-list


Re: CSV performance

2009-04-27 Thread Peter Otten
psaff...@googlemail.com wrote:

> I'm using the CSV library to process a large amount of data - 28
> files, each of 130MB. Just reading in the data from one file and
> filing it into very simple data structures (numpy arrays and a
> cstringio) takes around 10 seconds. If I just slurp one file into a
> string, it only takes about a second, so I/O is not the bottleneck. Is
> it really taking 9 seconds just to split the lines and set the
> variables?
> 
> Is there some way I can improve the CSV performance? 

My ideas:

(1) Disable cyclic garbage collection while you read the file into your data
structure:

import gc

gc.disable()
# create many small objects that you want to keep
gc.enable() 


(2) If your data contains only numerical data without quotes use

numpy.fromfile()

Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: CSV performance

2009-04-27 Thread Tim Chase

I'm using the CSV library to process a large amount of data -
28 files, each of 130MB. Just reading in the data from one
file and filing it into very simple data structures (numpy
arrays and a cstringio) takes around 10 seconds. If I just
slurp one file into a string, it only takes about a second, so
I/O is not the bottleneck. Is it really taking 9 seconds just
to split the lines and set the variables?


You've omitted one important test:  spinning through the file 
with csv-parsing, but not doing an "filing it into very simple 
data structures".  Without that metric, there's no way to know 
whether the csv module is at fault, or if you're doing something 
malperformant with the data-structures.


-tkc



--
http://mail.python.org/mailman/listinfo/python-list


Re: Help AIX 5.3 build on Python-3.1a2

2009-04-27 Thread pruebauno
On Apr 26, 5:14 am, Jeroen Ruigrok van der Werven  wrote:
> -On [20090425 19:17], Aahz (a...@pythoncraft.com) wrote:
>
> >In article 
> >,
> >  wrote:
> >>"Include/token.h", line 42.9: 1506-213 (S) Macro name TILDE cannot be
> >>redefined.
> >>"Include/token.h", line 42.9: 1506-358 (I) "TILDE" is defined on line
> >>250 of /usr/include/sys/ioctl.h.
>
> >Can you try trimming down the compilation to a small reproducible case?
>
> I thought it was already clear from what was provided?
>
> Include/token.h has a #define for TILDE and apparently AIX has a #define for
> TILDE in /usr/include/sys/ioctl.h as well. So you can a redefinition.
>
> One way around it, depending how AIX protects headers might be to change
> Include/token.h to either:
>
> #if defined(_SYS_IOCTL_H_)
> #undef TILDE
> #define TILDE           32
> #endif
>
> or
>
> #if defined(aix)
> #undef TILDE
> #define TILDE           32
> #endif
>
> --
> Jeroen Ruigrok van der Werven  / asmodai
> イェルーン ラウフロック ヴァン デル ウェルヴェンhttp://www.in-nomine.org/|http://www.rangaku.org/| 
> GPG: 2EAC625B
> A rose is a rose is a rose is a rose...

Thanks Jeroen. I know that AIX isn't as supported as other platforms,
but I thought it wouldn't hurt to ask anyway. At least now everybody
can search for that particular problem and find something. I will
experiment a little bit and see if I make it compile.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Web based application development using python

2009-04-27 Thread Scott David Daniels

Rahul wrote:

Hello all,

I have two questions
1)  When will be python3.1 (final) get released? (The date should be
appropriate (proposed), it must be the span in between which there are
chances of release)

Go to http://www.puthon.org
Click on Core Development
Click on PEP Index
under  Other Informational PEPs, find
 I   375  Python 3.1 Release Schedule
Click on that to get to
http://www.python.org/dev/peps/pep-0375/
However, if you go the way I described, you may find more
interesting stuff along the way.


2)  I have my web based application written using mod_python
a.  It should be more based on framework type.
b.  It should have all the features present in mod_python.

These two goals conflict.  You'll need to use your brain to discover
what is best for your application.  In general "have all the features
of" and "but better" conflict.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: CSV performance

2009-04-27 Thread psaff...@googlemail.com
Thanks for your replies. Many apologies for not including the right
information first time around. More information is below.

I have tried running it just on the csv read:

import time
import csv

afile = "largefile.txt"

t0 = time.clock()

print "working at file", afile
reader = csv.reader(open(afile, "r"), delimiter="\t")
for row in reader:
x,y,z = row


t1 = time.clock()

print "finished: %f.2" % (t1 - t0)


$ ./largefilespeedtest.py
working at file largefile.txt
finished: 3.86.2


A tiny bit of background on the final application: this is biological
data from an affymetrix platform. The csv files are a chromosome name,
a coordinate and a data point, like this:

chr13754914 1.19828
chr13754950 1.56557
chr13754982 1.52371

In the "simple data structures" cod below, I do some jiggery pokery
with the chromosome names to save me storing the same string millions
of times.


import csv
import cStringIO
import numpy
import time

afile = "largefile.txt"

chrommap = {'chrY': 'y', 'chrX': 'x', 'chr13': 'c',
'chr12': 'b', 'chr11': 'a', 'chr10': '0',
'chr17': 'g', 'chr16': 'f', 'chr15': 'e',
'chr14': 'd', 'chr19': 'i', 'chr18': 'h',
'chrM': 'm', 'chr22': 'l', 'chr20': 'j',
'chr21': 'k', 'chr7': '7', 'chr6': '6',
'chr5': '5', 'chr4': '4', 'chr3': '3',
'chr2': '2', 'chr1': '1', 'chr9': '9', 'chr8': '8'}


def getFileLength(fh):
wholefile = fh.read()
numlines = wholefile.count("\n")
fh.seek(0)
return numlines

count = 0
print "reading affy file", afile
fh = open(afile)
n = getFileLength(fh)
chromio = cStringIO.StringIO()
coords = numpy.zeros(n, dtype=int)
points = numpy.zeros(n)

t0 = time.clock()
reader = csv.reader(fh, delimiter="\t")
for row in reader:
if not row:
continue
chrom, coord, point = row
mappedc = chrommap[chrom]
chromio.write(mappedc)
coords[count] = coord
points[count] = point
count += 1
t1 = time.clock()

print "finished: %f.2" % (t1 - t0)


$ ./affyspeedtest.py
reading affy file largefile.txt
finished: 15.54.2


Thanks again (tugs forelock),

Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Lisp mentality vs. Python mentality

2009-04-27 Thread Marco Mariani

Scott David Daniels wrote:


I don't remember who, but something famously said, in effect:
Debugging is hard, maybe twice as hard as writing the code in
the first place.  Unless you are one of those nonexistent few


He would be the K in K&R.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a maximum size to a Python program?

2009-04-27 Thread Mike Kent
On Apr 27, 1:49 am, John Machin  wrote:

> > I am
> > having a look at eval and exec
>
> WRONG WAY
> GO BACK

+1 QOTW
--
http://mail.python.org/mailman/listinfo/python-list


Re: CSV performance

2009-04-27 Thread grocery_stocker
On Apr 27, 5:15 am, Peter Otten <__pete...@web.de> wrote:
> psaff...@googlemail.com wrote:
> > I'm using the CSV library to process a large amount of data - 28
> > files, each of 130MB. Just reading in the data from one file and
> > filing it into very simple data structures (numpy arrays and a
> > cstringio) takes around 10 seconds. If I just slurp one file into a
> > string, it only takes about a second, so I/O is not the bottleneck. Is
> > it really taking 9 seconds just to split the lines and set the
> > variables?
>
> > Is there some way I can improve the CSV performance?
>
> My ideas:
>
> (1) Disable cyclic garbage collection while you read the file into your data
> structure:
>
> import gc
>
> gc.disable()
> # create many small objects that you want to keep
> gc.enable()
>
> (2) If your data contains only numerical data without quotes use
>
> numpy.fromfile()
>

How would disabling the cyclic garbage collection make it go faster in
this case?

--
http://mail.python.org/mailman/listinfo/python-list


Re: Help AIX 5.3 build on Python-3.1a2

2009-04-27 Thread Jeroen Ruigrok van der Werven
-On [20090427 15:00], prueba...@latinmail.com (prueba...@latinmail.com) wrote:
>Thanks Jeroen. I know that AIX isn't as supported as other platforms,
>but I thought it wouldn't hurt to ask anyway. At least now everybody
>can search for that particular problem and find something. I will
>experiment a little bit and see if I make it compile.

I'll be interested to see if that fixes it. I have had to support a bunch of
different Unix systems over the years compile-wise, but I don't think AIX
was one of them though, so I might be a bit rusty there.

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
What is the short meaning of this long speech..?
--
http://mail.python.org/mailman/listinfo/python-list


Re: CSV performance

2009-04-27 Thread Peter Otten
grocery_stocker wrote:

> On Apr 27, 5:15 am, Peter Otten <__pete...@web.de> wrote:
>> psaff...@googlemail.com wrote:
>> > I'm using the CSV library to process a large amount of data - 28
>> > files, each of 130MB. Just reading in the data from one file and
>> > filing it into very simple data structures (numpy arrays and a
>> > cstringio) takes around 10 seconds. If I just slurp one file into a
>> > string, it only takes about a second, so I/O is not the bottleneck. Is
>> > it really taking 9 seconds just to split the lines and set the
>> > variables?
>>
>> > Is there some way I can improve the CSV performance?
>>
>> My ideas:
>>
>> (1) Disable cyclic garbage collection while you read the file into your
>> data structure:
>>
>> import gc
>>
>> gc.disable()
>> # create many small objects that you want to keep
>> gc.enable()
>>
>> (2) If your data contains only numerical data without quotes use
>>
>> numpy.fromfile()
>>
> 
> How would disabling the cyclic garbage collection make it go faster in
> this case?

When Python creates many objects and doesn't release any it is assumed that
they are kept due to cyclic references. When you know that you actually
want to keep all those objects you can temporarily disable garbage
collection. E. g.:

$ cat gcdemo.py
import time
import sys
import gc


def main(float=float):
if "-d" in sys.argv:
gc.disable()
status = "disabled"
else:
status = "enabled"
all = []
append = all.append
start = time.time()
floats = ["1.234"] * 10
assert len(set(map(id, map(float, floats == len(floats)
for _ in xrange(10**6):
append(map(float, floats))
print time.time() - start, "(garbage collection %s)" % status


main()

$ python gcdemo.py -d
11.6144971848 (garbage collection disabled)
$ python gcdemo.py
15.5317759514 (garbage collection enabled)

Of course I don't know whether this is actually a problem for the OP's code.

Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: CSV performance

2009-04-27 Thread Tim Chase

I have tried running it just on the csv read:

...

print "finished: %f.2" % (t1 - t0)


I presume you wanted "%.2f" here. :)


$ ./largefilespeedtest.py
working at file largefile.txt
finished: 3.86.2


So just the CSV processing of the file takes just shy of 4 
seconds and you said that just the pure file-read took about a 
second, so that leaves about 3 seconds for CSV processing (or 
about 1/3 of the total runtime).  In your code example in your 
2nd post (with the timing in it), it looks like it took 15+ 
seconds, meaning the csv code is a mere 1/5 of the runtime.  I 
also notice that you're reading the file once to find the length, 
and reading again to process it.



The csv files are a chromosome name,
a coordinate and a data point, like this:

chr13754914 1.19828
chr13754950 1.56557
chr13754982 1.52371


Depending on the simplicity of the file-format (assuming nothing 
like spaces/tabs in the chromosome name, which your dictionary 
seems to indicate is the case), it may be faster to use .split() 
to do the work:


  for line in file(afile):
 a,b,c = line.rstrip('\n\r').split()

The csv module does a lot of smart stuff that it looks like you 
may not need.


However, you're still only cutting from that 3-second subset of 
your total time.  Focusing on the "filing it into very simple 
data structures" will likely net you greater improvements. I 
don't have much experience with numpy, so I can't offer much to 
help.  However, rather than reading the file twice, you might try 
a general heuristic, assuming lines are no longer than N 
characters (they look like they're each 20 chars + a newline) and 
then using "filesize/N" to estimate an adequately sized array. 
Using stat() on a file to get its size will be a heckuva lot 
faster than reading the whole file.  I also don't know the 
performance of cStringIO.CString() with lots of appending. 
However, since each write is just a character, you might do well 
to use the array module (unless numpy also has char-arrays) to 
preallocate n chars just like you do with your ints and floats:


  chromeio[count] = chrommap[chrom]
  coords[count] = coord
  points[count] = point
  count += 1

Just a few ideas to try.

-tkc





--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a maximum size to a Python program?

2009-04-27 Thread Martin P. Hellwig

Carbon Man wrote:
I have a program that is generated from a generic process. It's job is to 
check to see whether records (replicated from another system) exist in a 
local table, and if it doesn't, to add them. 


To answer the topic question, it would be limited to the memory your 
platform can allocate and I guess that the most critical part would be 
if you run out of memory for handling the namespace references.


However my magic 8 ball whispers to me that the provided solution tries 
to be smarter than the given problem requires, which is not a good 
thing. If so and if possible, please provide a more detailed explanation 
of the actual problem you want to solve instead of the problem you 
currently have with the provided solution.


--
MPH
http://blog.dcuktec.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: CSV performance

2009-04-27 Thread Peter Otten
psaff...@googlemail.com wrote:

> Thanks for your replies. Many apologies for not including the right
> information first time around. More information is below.
> 
> I have tried running it just on the csv read:

> $ ./largefilespeedtest.py
> working at file largefile.txt
> finished: 3.86.2
> 
> 
> A tiny bit of background on the final application: this is biological
> data from an affymetrix platform. The csv files are a chromosome name,
> a coordinate and a data point, like this:
> 
> chr1  3754914 1.19828
> chr1  3754950 1.56557
> chr1  3754982 1.52371
> 
> In the "simple data structures" cod below, I do some jiggery pokery
> with the chromosome names to save me storing the same string millions
> of times.

> $ ./affyspeedtest.py
> reading affy file largefile.txt
> finished: 15.54.2

It looks like most of the time is not spent in the csv.reader().
Here's an alternative way to read your data:

rows = fh.read().split()
coords = numpy.array(map(int, rows[1::3]), dtype=int)
points = numpy.array(map(float, rows[2::3]), dtype=float)
chromio.writelines(map(chrommap.__getitem__, rows[::3]))

Do things improve if you simplify your code like that?

Peter
--
http://mail.python.org/mailman/listinfo/python-list


IDE for Win CE?

2009-04-27 Thread Albert-jan Roskam

Hi,

A colleague of mine is looking for a Python IDE for Windows CE.
Does anybody happen to know what is a good choice?

Thanks,
AJ


  
--
http://mail.python.org/mailman/listinfo/python-list


Re: Lisp mentality vs. Python mentality

2009-04-27 Thread Paul Rubin
Carl Banks  writes:
> > > Presumably you have to protect objects to share them?  There you go:
> > > anytime you try to acquire a lock have the thread check to see whether
> > > to abort.
> >
> > Normally, acquiring a lock doesn't require running code in other
> > threads, at least in the uncontended case.  If you have to switch
> > threads twice in order to acquire a lock, your implementation could
> > use some improvement.
> 
> Come on, you're just making stuff up.  How the *hell* do you get
> switching threads twice out of that?  

I think I mis-read your suggestion.  I thought you meant to query
another thread before acquiring a lock.

Anyway, the usual reason to want to kill a thread is that it's become
unresponsive for some reason, while holding onto some resource like a
lock or a bound socket.  This would be in the category of fault
recovery from conditions that weren't expected ahead of time.

Another situation is when you want to just stop the program
altogether, similar to kill -9'ing it, with no attempt to shut down
gracefully.  Kind of a global ctrl-C.  Right now there is no way to do
that for a multithreaded program except by literally sending a process
kill, which is pretty ugly.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Get item from set

2009-04-27 Thread Aahz
In article ,
Peter Otten  <__pete...@web.de> wrote:
>
>Here's a trick to find the actual element. I think Raymond Hettinger posted
>an implementation of this idea recently, but I can't find it at the moment.

Your code is inverted from Raymond's:

http://code.activestate.com/recipes/499299/

class _CaptureEq:
'Object wrapper that remembers "other" for successful equality tests.'
def __init__(self, obj):
self.obj = obj
self.match = None
def __eq__(self, other):
result = (self.obj == other)
if result:
self.match = other
return result
# support hash() or anything else needed by __ contains__
def __getattr__(self, name):  
return getattr(self.obj, name)

def get_equivalent(container, item, default=None):
'''Gets the specific container element matched by: "item in container".

Useful for retreiving a canonical value equivalent to "item".  For
example, a caching or interning application may require fetching a
single representativ e instance from many possible equivalent
instances).

>>> get_equivalent(set([1, 2, 3]), 2.0)   # 2.0 is equivalent to 2
2
>>> get_equivalent([1, 2, 3], 4, default=0)
0
'''
t = _CaptureEq(item)
if t in container:
return t.match
return default
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a maximum size to a Python program?

2009-04-27 Thread Aahz
In article ,
Steven D'Aprano   wrote:
>On Sun, 26 Apr 2009 21:51:00 -0700, John Machin wrote:
>>
>> ἐδάκρυσεν ὁ Ἰησοῦς
>
>Alright, I give up. Is that APL code? *grin*

base64 encoding
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair
--
http://mail.python.org/mailman/listinfo/python-list


Re: Lisp mentality vs. Python mentality

2009-04-27 Thread Zamnedix
On Apr 24, 11:06 pm, Carl Banks  wrote:
> In answering the recent question by Mark Tarver, I think I finally hit
> on why Lisp programmers are the way they are (in particular, why they
> are often so hostile to the "There should only be one obvious way to
> do it" Zen).
>
> Say you put this task to a Lisp and a Python programmer: Come up with
> a good, generic, reusable way to compare two lists.  What are their
> respective trains of thought?
>
> Lisp programmer:
>
> Well, there is a standard function called mismatch that does it, but I
> can't recommend it.  First of all, you don't know where that
> function's been.  Anyone and their mother could have worked on it, did
> they have good, sound programming practice in mind when they wrote
> it?  Of course not.  Let's be real here, we have to implement this by
> hand.
>
> (defun lists-are-equal (a b)
>    (or (and (not a) (not b))
>        (and (= (car a) (car b)) (lists-are-equal (cdr a) (cdr b
>
> There, much better than the standard function, and better yet, it's in
> the *absolute minimal form possible*.  There is no way to express list
> comparison in a more reduced form.  It's almost erotic how awesome it
> is.  I'm---whoa, ok, I'm getting a little excited now, settle down.
> Well, come to think of it, that's really not that good.  First of all
> it's a function.  I mean, it just sits there and does nothing till you
> call it.  How boring is that?  It can't react to the current
> situation.  Plus it compares all lists the same way, and that is
> really inefficient.  Every list compare is a new problem.  Different
> lists need different comparative strategies.  This function simply
> won't do.  I need a macro that can intelligently compile the right
> list compare methodology in.  For instance, if we want to compare two
> lists that are known at compile time, we don't want to waste time
> comparing them at runtime.  No, the macro must detect constant
> arguments and special case them.  Good start.  Now, we have to
> consider the conditions this comparison is being done under.  If the
> user is passing the result of a sort to this macro, it's almost
> certain that they are trying to see whether the lists have the same
> elements.  We can do that a lot more efficiently with a countset.  So
> let's have the macro check to see if the forms passed to it are all
> sort calls.  Better yet, let's check for my own powerful sort macro.
> Hmm.  Wait... I think my 4600-line sort macro already checks its
> calling context to see if its results are being fed to a list
> comparison.  I'll have to refactor that together with this macro.  Ok,
> good, now I am sure other users will eventually want to customize list
> comparison for their own use, after all every list comparison is
> different and I can't possibly anticipate all of them.  A user needs
> to be able to adapt to the situation, so it's vitally important to
> create a plug-in infrastructure to give them that flexibility.  Now,
> what about exceptions, there's a millions ways to deal with that...
>
> ...and so on until eyelids can no longer stay open
>
> Python programmer:
>
> a == b.  Next question.
>
> Carl Banks, who might be exaggerating
>
> ...a little.

Hahaha. I love it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Thread-killing, round 666 (was Re: Lisp mentality vs. Python mentality)

2009-04-27 Thread Aahz
In article <42cebb2b-0361-416c-8932-9371da50a...@y6g2000prf.googlegroups.com>,
Vsevolod   wrote:
>
>As well I'd like to outline, that, IMO, your answer exhibits the
>common attitude among pythonistas: everything should be done in one
>true way, which is the best option (and that is how it's implemented
>in the current version of the language). 

Did you see my comment about Java?  This particular issue has little to
do with Python.  I won't disagree that what you're describing is
sometimes a problem in the Python community, but you're picking the
wrong issue to claim its relevance.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair
--
http://mail.python.org/mailman/listinfo/python-list


getattr on a function

2009-04-27 Thread Mr SZ

Hi all,

Is it possible to call functions using getattr. I have written a simple script 
with functions that call either SSL, TLS or plain functionality.

something like:
def func():
  ...

def funcSSL():
  ...

def funcTLS():
  ...

Now, based on my args I would like to call either one of them. In my case, I 
can't seem to figure out what my object would be when I call getattr(object, 
'func'+) !

" life isn't heavy enough,it flies away and floats far above action"


  Enjoy a safer web experience. Upgrade to the new Internet Explorer 8 
optimised for Yahoo!7. Get it now.
--
http://mail.python.org/mailman/listinfo/python-list


Best way to evaluate boolean expressions from strings?

2009-04-27 Thread Gustavo Narea
Hello, everybody.

I need to evaluate boolean expressions like "foo == 1" or "foo ==1 and
(bar > 2 or bar == 0)" which are defined as strings (in a database or
a plain text file, for example). How would you achieve this?

These expressions will contain placeholders for Python objects (like
"foo" and "bar" in the examples above). Also, the Python objects that
will get injected in the expression will support at least one of the
following operations: "==", "!=", ">", "<", ">=", "<=", "&", "|",
"in".

I don't need the ability to import modules, define classes, define
functions, etc. I just need to evaluate boolean expressions defined as
strings (using the Python syntax is fine, or even desirable).

Here's a complete example:

I have the "user_ip" and "valid_ips" placeholders defined in Python as
follows:
"""
user_ip = '111.111.111.111'

class IPCollection(object):
def __init__(self, *valid_ips):
self.valid_ips = valid_ips
def __contains__(self, value):
return value in self.valid_ips

valid_ips = IPCollection('222.222.222.222', '111.111.111.111')
"""

So the following boolean expressions given as strings should be
evaluated as:
 * "user_ip == '127.0.0.1'"  --->  False
 * "user_ip == '127.0.0.1' or user_ip in valid_ips"  --->  True
 * "user_ip not in valid_ips" ---> False

That's it. How would you deal with this? I would love to re-use
existing stuff as much as possible, that works in Python 2.4-2.6 and
also that has a simple syntax (these expressions may not be written by
technical people; hence I'm not sure about using TALES).

Thanks in advance!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Thread-killing, round 666 (was Re: Lisp mentality vs. Python mentality)

2009-04-27 Thread Vsevolod
On Apr 27, 7:16 pm, a...@pythoncraft.com (Aahz) wrote:
> Did you see my comment about Java?  This particular issue has little to
> do with Python.  I won't disagree that what you're describing is
> sometimes a problem in the Python community, but you're picking the
> wrong issue to claim its relevance.

OK, I'm not a big expert in Python. That was just the thing, that was
important to me recently. I won't claim, that it's regularly a problem
with Python, although from reading Guido's blog I get that impression.
(Well, I understand, that's how BDFLs should behave :)
Yet there was no response to my point, that the original example was
not realistically depicting the Lisp world, while more characteristic
of the Python one.

Best regards,
Vsevolod
--
http://mail.python.org/mailman/listinfo/python-list


Re: getattr on a function

2009-04-27 Thread Peter Otten
Mr SZ wrote:

> Is it possible to call functions using getattr. I have written a simple
> script with functions that call either SSL, TLS or plain functionality.
> 
> something like:
> def func():
>   ...
> 
> def funcSSL():
>   ...
> 
> def funcTLS():
>   ...
> 
> Now, based on my args I would like to call either one of them. In my case,
> I can't seem to figure out what my object would be when I call
> getattr(object, 'func'+) !

>From within the module:

encryption = ...
f = globals()["func" + encryption]
f(...)


In other modules, assuming the module containing the function is
called 'module':

import module

encryption = ...
f = getattr(module, "func" + encryption)
f(...)

Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Thread-killing, round 666 (was Re: Lisp mentality vs. Python mentality)

2009-04-27 Thread Aahz
In article <22272831-8d11-42d6-a587-9a2ab4712...@p6g2000pre.googlegroups.com>,
Vsevolod   wrote:
>
>Yet there was no response to my point, that the original example was
>not realistically depicting the Lisp world, while more characteristic
>of the Python one.

That's because there's no response to make; the original post was a joke,
and trying to have a serious discussion about it rarely excites people.

If you want to talk about Python and problems you're running into, you
should start a new thread.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a maximum size to a Python program?

2009-04-27 Thread Wolfgang Rohdewald
On Montag, 27. April 2009, John Machin wrote:
> ἐδάκρυσεν ὁ Ἰησοῦς

και εγώ

+1

-- 
Wolfgang
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to evaluate boolean expressions from strings?

2009-04-27 Thread Gabriel Genellina
En Mon, 27 Apr 2009 14:03:01 -0300, Gustavo Narea   
escribió:



I need to evaluate boolean expressions like "foo == 1" or "foo ==1 and
(bar > 2 or bar == 0)" which are defined as strings (in a database or
a plain text file, for example). How would you achieve this?


This recent thread may be of interest:

Safe eval of moderately simple math expressions
http://groups.google.com/group/comp.lang.python/t/c1aff28494ab5b59/

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to evaluate boolean expressions from strings?

2009-04-27 Thread Peter Otten
Gustavo Narea wrote:

> I need to evaluate boolean expressions like "foo == 1" or "foo ==1 and
> (bar > 2 or bar == 0)" which are defined as strings (in a database or
> a plain text file, for example). How would you achieve this?
> 
> These expressions will contain placeholders for Python objects (like
> "foo" and "bar" in the examples above). Also, the Python objects that
> will get injected in the expression will support at least one of the
> following operations: "==", "!=", ">", "<", ">=", "<=", "&", "|",
> "in".
> 
> I don't need the ability to import modules, define classes, define
> functions, etc. I just need to evaluate boolean expressions defined as
> strings (using the Python syntax is fine, or even desirable).
> 
> Here's a complete example:
> 
> I have the "user_ip" and "valid_ips" placeholders defined in Python as
> follows:
> """
> user_ip = '111.111.111.111'
> 
> class IPCollection(object):
> def __init__(self, *valid_ips):
> self.valid_ips = valid_ips
> def __contains__(self, value):
> return value in self.valid_ips
> 
> valid_ips = IPCollection('222.222.222.222', '111.111.111.111')
> """
> 
> So the following boolean expressions given as strings should be
> evaluated as:
>  * "user_ip == '127.0.0.1'"  --->  False
>  * "user_ip == '127.0.0.1' or user_ip in valid_ips"  --->  True
>  * "user_ip not in valid_ips" ---> False
> 
> That's it. How would you deal with this? I would love to re-use
> existing stuff as much as possible, that works in Python 2.4-2.6 and
> also that has a simple syntax (these expressions may not be written by
> technical people; hence I'm not sure about using TALES).

exprs = [
"user_ip == '127.0.0.1'",
"user_ip == '127.0.0.1' or user_ip in valid_ips",
"user_ip not in valid_ips"]
for expr in exprs:
print expr, "-->", eval(expr)

Be warned that a malicious user can make your program execute arbitrary
python code; if you put the input form for expressions on the internet
you're toast.

Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: getattr on a function

2009-04-27 Thread John Machin
On Apr 28, 2:30 am, Mr SZ  wrote:
> Hi all,
>
> Is it possible to call functions using getattr. I have written a simple 
> script with functions that call either SSL, TLS or plain functionality.
>
> something like:
> def func():
>   ...
>
> def funcSSL():
>   ...
>
> def funcTLS():
>   ...
>
> Now, based on my args I would like to call either one of them. In my case, I 
> can't seem to figure out what my object would be when I call getattr(object, 
> 'func'+) !

A function is an attribute of the module that the function is defined
in. If you don't want to hard-code the name of the module,
you can use the fact that the name __name__ is bound to the current
module, and sys.modules provides a mapping from module names to the
actual module objects.

So: getattr(foomodule, 'func' + encr)
or: getattr(sys.modules[__name__], 'func' + encr)

Or, in the same module you could have:

encrfuncdict = {
   'SSL': funcSSL,
   # etc
   }

and your call would be encrfuncdict[encryption](arg1, arg2, ...)

*AND* folk reading your code wouldn't have to write in and ask what
all that getattr() stuff was doing ;-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: ActiveState Komodo Edit?

2009-04-27 Thread Trent Mick

John Doe wrote:

Another question...
There is a region on the left margin to the left of the code and to


BTW, we call those regions "gutters" of the editing area.


the right of the outlining area, in between the code and the
outlining area. It looks like an area used to select lines. But
dragging the pointer down that area does nothing apparent. Isn't
that supposed to select lines of text? Maybe I have colors set
wrong, but selected text does show up when selected other ways. Or 
maybe that area is nonfunctional, left over from the IDE?


If you make line numbers visible (View -> View Line Numbers) then you 
can do what you want in the line numbers gutter.


Cheers,
Trent

--
Trent Mick
trentm at activestate.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a maximum size to a Python program?

2009-04-27 Thread Gabriel Genellina

En Mon, 27 Apr 2009 13:12:29 -0300, Aahz  escribió:


In article ,
Steven D'Aprano   wrote:

On Sun, 26 Apr 2009 21:51:00 -0700, John Machin wrote:


ἐδάκρυσεν ὁ Ἰησοῦς


Alright, I give up. Is that APL code? *grin*


base64 encoding


Yes, my news client kindly decoded it for me.
It looks like Greek, and I can transliterate the last word as Iesous, so  
it might be some kind of Biblical reference. But I don't have the  
slightiest idea of what that means...


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Cannot find text in *.py files with Windows Explorer?

2009-04-27 Thread Terry Reedy

John Doe wrote:

John Doe  wrote:

...


Another file manager, FreeCommander, does find text in Python files.


However... It does not have Undo! Potentially risky.


Undo is an editor function.  I do not believe Windows Explore has Undo 
either.


--
http://mail.python.org/mailman/listinfo/python-list


Re: and [True,True] --> [True, True]?????

2009-04-27 Thread Terry Reedy

jazbees wrote:

On Apr 25, 12:11 pm, Duncan Booth 
wrote:

jazbees  wrote:

hasvowels = lambda x:max([y in x for y in "aeiou"])
hasvowels("parsnips")

True

hasvowels("sfwdkj")

False

Do you object to using def to define functions?


Not at all.  Do you object to my use of lambdas?  I'm not aware of
anything that says it's bad form to define a function using a lambda
when the only thing that a function does is immediately return some
calculated value.


The difference between

hasvowels = lambda x:max([y in x for y in "aeiou"])

and

def hasvowels(x): return max([y in x for y in "aeiou"])

is that the first is 4 chars shorter, but the result has a generic 
.__name__ attribute of '' insteand of the specific 'hasvowels', 
which is definitely more useful.  Given this and the that the main 
purpose of lambda is to avoid a local name binding, many consider its 
use in 'name = lambda...' to be bad form.


tjr

--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a maximum size to a Python program?

2009-04-27 Thread Gabriel Genellina
En Mon, 27 Apr 2009 14:50:23 -0300, Gabriel Genellina  
 escribió:



En Mon, 27 Apr 2009 13:12:29 -0300, Aahz  escribió:


In article ,
Steven D'Aprano   wrote:

On Sun, 26 Apr 2009 21:51:00 -0700, John Machin wrote:


ἐδάκρυσεν ὁ Ἰησοῦς


Alright, I give up. Is that APL code? *grin*


base64 encoding


Yes, my news client kindly decoded it for me.
It looks like Greek, and I can transliterate the last word as Iesous, so  
it might be some kind of Biblical reference. But I don't have the  
slightiest idea of what that means...


Answering to myself: Jesus wept.
http://en.wikipedia.org/wiki/Jesus_wept#Use_as_an_expletive

(This reminds me a book by Ellery Queen that I read a (very long) time  
ago, the phrase "And Ellery cried" was a complete chapter by itself. I  
didn't catch the Gospel reference that time - I thought it was just a  
matter of style, a very short (and dramatic) chapter).


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: CSV performance

2009-04-27 Thread Scott David Daniels

psaff...@googlemail.com wrote:

Thanks for your replies. Many apologies for not including the right
information first time around. More information is below

Here is another way to try (untested):

import numpy
import time

chrommap = dict(chrY='y', chrX='x', chr13='c', chr12='b', chr11='a',
chr10='0', chr17='g', chr16='f', chr15='e', chr14='d',
chr19='i', chr18='h', chrM='m', chr22='l', chr20='j',
chr21='k', chr7='7', chr6='6', chr5='5', chr4='4',
chr3='3', chr2='2', chr1='1', chr9='9', chr8='8')

def consume_file(file_name, chunks)
numpy.zeros(size_guess)
lx = []
cx = []
px = []
block = []
with open(file_name) as fh:
for line in enumerate(fh):
chrom, coord, point = row.split()
lx.append(chrommap[chrom])
cx.append(coord)
px.append(point)
if len(cx) >= chunks:
block.append(.''.join(lx))
block.append(numpy.array(cx, dtype=int))
block.append(numpy.array(px, dtype=float))
lx = []
cx = []
px = []
if lx:
block.append(.''.join(lx))
block.append(numpy.array(cx))
block.append(numpy.array(px))

return (''.join(block[0::3]),
numpy.concatenate(block[1::3]),
numpy.concatenate(block[2::3]))


# The following repeats 128, to avoid initial read issues.
# Treat the diff twixt the two 128s as read overhead.
for CHUNKS in 128, 128, 256, 1024, 4096, 16384:
t0 = time.clock()
letters, coords, points = consume_file("largefile.txt", CHUNKS)
t1 = time.clock()
print "finished %s in %s chunks: %f.2" % (
 len(letters), CHUNKS, t1 - t0)


--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help AIX 5.3 build on Python-3.1a2

2009-04-27 Thread pruebauno
On Apr 27, 10:26 am, Jeroen Ruigrok van der Werven  wrote:
> -On [20090427 15:00], prueba...@latinmail.com (prueba...@latinmail.com) wrote:
>
> >Thanks Jeroen. I know that AIX isn't as supported as other platforms,
> >but I thought it wouldn't hurt to ask anyway. At least now everybody
> >can search for that particular problem and find something. I will
> >experiment a little bit and see if I make it compile.
>
> I'll be interested to see if that fixes it. I have had to support a bunch of
> different Unix systems over the years compile-wise, but I don't think AIX
> was one of them though, so I might be a bit rusty there.
>
> --
> Jeroen Ruigrok van der Werven  / asmodai
> イェルーン ラウフロック ヴァン デル ウェルヴェンhttp://www.in-nomine.org/|http://www.rangaku.org/| 
> GPG: 2EAC625B
> What is the short meaning of this long speech..?

Yes, I tried them and either way fixes it. But this was with version 6
of the xlc compiler and it later gave me this error:

xlc_r -q64 -c  -DNDEBUG -O2  -I. -IInclude -I./Include   -
DPy_BUILD_CORE -o Python/symtable.o Python/symtable.c

"Python/symtable.c", line 767.50: 1506-068 (S) Operation between types
"struct _object*" and "int" is not allowed.
"Python/symtable.c", line 826.55: 1506-068 (S) Operation between types
"struct _object*" and "int" is not allowed.
make: 1254-004 The error code from the last command is 1.

I gave up and found a machine with xlc version 8 installed. Using that
version gave me a bunch of warnings instead but it compiled. Just for
the curious this is (more or less) what it looks like (long text
follows!):

(//ptst/Python-3.1a2) > make
xlc_r -q64 -c  -DNDEBUG -O2  -I. -IInclude -I./Include   -
DPy_BUILD_CORE -o Modules/python.o ./Modules/python.c
xlc_r -q64 -c  -DNDEBUG -O2  -I. -IInclude -I./Include   -
DPy_BUILD_CORE -o Parser/acceler.o Parser/acceler.c
"Include/token.h", line 42.9: 1506-236 (W) Macro name TILDE has been
redefined.
"Include/token.h", line 42.9: 1506-358 (I) "TILDE" is defined on line
250 of /usr/include/sys/ioctl.h.
xlc_r -q64 -c  -DNDEBUG -O2  -I. -IInclude -I./Include   -
DPy_BUILD_CORE -o Parser/grammar1.o Parser/grammar1.c
"Include/token.h", line 42.9: 1506-236 (W) Macro name TILDE has been
redefined.
"Include/token.h", line 42.9: 1506-358 (I) "TILDE" is defined on line
250 of /usr/include/sys/ioctl.h.
xlc_r -q64 -c  -DNDEBUG -O2  -I. -IInclude -I./Include   -
DPy_BUILD_CORE -o Parser/listnode.o Parser/listnode.c
"Include/token.h", line 42.9: 1506-236 (W) Macro name TILDE has been
redefined.
"Include/token.h", line 42.9: 1506-358 (I) "TILDE" is defined on line
250 of /usr/include/sys/ioctl.h.
xlc_r -q64 -c  -DNDEBUG -O2  -I. -IInclude -I./Include   -
DPy_BUILD_CORE -o Parser/node.o Parser/node.c
xlc_r -q64 -c  -DNDEBUG -O2  -I. -IInclude -I./Include   -
DPy_BUILD_CORE -o Parser/parser.o Parser/parser.c
"Include/token.h", line 42.9: 1506-236 (W) Macro name TILDE has been
redefined.
"Include/token.h", line 42.9: 1506-358 (I) "TILDE" is defined on line
250 of /usr/include/sys/ioctl.h.
"Parser/parser.c", line 32.31: 1506-1298 (W) The subscript 1500 is out
of range. The valid range is 0 to 1499.
"Parser/parser.c", line 293.45: 1506-1298 (W) The subscript 1500 is
out of range. The valid range is 0 to 1499.
"Parser/parser.c", line 314.29: 1506-1298 (W) The subscript 1500 is
out of range. The valid range is 0 to 1499.
xlc_r -q64 -c  -DNDEBUG -O2  -I. -IInclude -I./Include   -
DPy_BUILD_CORE -o Parser/parsetok.o Parser/parsetok.c
"Include/token.h", line 42.9: 1506-236 (W) Macro name TILDE has been
redefined.
"Include/token.h", line 42.9: 1506-358 (I) "TILDE" is defined on line
250 of /usr/include/sys/ioctl.h.
xlc_r -q64 -c  -DNDEBUG -O2  -I. -IInclude -I./Include   -
DPy_BUILD_CORE -o Parser/bitset.o Parser/bitset.c
xlc_r -q64 -c  -DNDEBUG -O2  -I. -IInclude -I./Include   -
DPy_BUILD_CORE -o Parser/metagrammar.o Parser/metagrammar.c
xlc_r -q64 -c  -DNDEBUG -O2  -I. -IInclude -I./Include   -
DPy_BUILD_CORE -o Parser/firstsets.o Parser/firstsets.c
"Include/token.h", line 42.9: 1506-236 (W) Macro name TILDE has been
redefined.
"Include/token.h", line 42.9: 1506-358 (I) "TILDE" is defined on line
250 of /usr/include/sys/ioctl.h.
xlc_r -q64 -c  -DNDEBUG -O2  -I. -IInclude -I./Include   -
DPy_BUILD_CORE -o Parser/grammar.o Parser/grammar.c
"Include/token.h", line 42.9: 1506-236 (W) Macro name TILDE has been
redefined.
"Include/token.h", line 42.9: 1506-358 (I) "TILDE" is defined on line
250 of /usr/include/sys/ioctl.h.
xlc_r -q64 -c  -DNDEBUG -O2  -I. -IInclude -I./Include   -
DP

Re: Cannot find text in *.py files with Windows Explorer?

2009-04-27 Thread John Doe
Terry Reedy  wrote:
> John Doe wrote:
>> John Doe  wrote:
>> 
>> ...
>> 
>>> Another file manager, FreeCommander, does find text in Python
>>> files. 
>> 
>> However... It does not have Undo! Potentially risky.
> 
> Undo is an editor function.  I do not believe Windows Explore has
> Undo either.

Besides Undo... editing functions like copy, paste, and move are all 
included in a file manager. You might not need that (Undo) safety 
feature... then again, some users think they do not need to keep a 
removable media backup copy of important files from their hard drive 
either.

Undo and other editing functions are part of a file manager. And Yes, 
Windows Explorer does include Undo. A file manager is too powerful to 
be without Undo, unless maybe it prompts the user every time 
files/folders are moved or deleted. 

Many have complained, but for some reason the author of FreeCommander 
does not care about that.


-- 
Interested in making Windows and games obey your verbal commands? 
Continuous command recognition (much easier than speech recognition)
can now be enabled using Naturally Speaking and freeware Dragonfly. 
See (comp.lang.beta) for discussion.
--
http://mail.python.org/mailman/listinfo/python-list


Re: ActiveState Komodo Edit?

2009-04-27 Thread John Doe
Trent Mick  wrote:

> John Doe wrote:

>> There is a region on the left margin to the left of the code 

> BTW, we call those regions "gutters" of the editing area.

Okay.

>> the right of the outlining area, in between the code and the
>> outlining area. It looks like an area used to select lines. But
>> dragging the pointer down that area does nothing apparent. 

> If you make line numbers visible (View -> View Line Numbers) then
> you can do what you want in the line numbers gutter.

I am using the free editor-only Komodo Edit. Apparently that does not
work here. 


-- 
Interested in making Windows and games obey your verbal commands? 
Continuous command recognition (much easier than speech recognition)
can now be enabled using Naturally Speaking and freeware Dragonfly. 
See (comp.lang.beta) for discussion.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Get item from set

2009-04-27 Thread Terry Reedy

Johannes Bauer wrote:

Hi group,

I have a very simple about sets. This is a minimal example:

#!/usr/bin/python
class x():
def __init__(self, y):
self.__y = y
def __eq__(self, other):
return self.__y == other.__y
def __hash__(self):
return hash(self.__y)

a = x("foo")
s = set([x("bar"), x("moo"), a])
z = x("foo")
print("z = ", z)
print(s)
for i in s:
print(i, i == a, i is a, i == z, i is z)

The problem is: two instances of x() are equal (__eq__ returns true),
but they are not identical. I have an equal element ("z"), but want to
get the *actual* element ("a") in the set. I.d. in the above example,
i'd like something like:

print(s.getelement(z) is a)
True

Is there something like the "getelement" function? How can I do what I want?


No. but you pratically wrote it: in your code, when i == z, then i is 
the element you want.


def getelement(sset, item):
  for i in sset:
if i == item: return i

The only use for this is see, though, is getting the representative of 
an equivalence class from any member thereof.


tjr

--
http://mail.python.org/mailman/listinfo/python-list


Re: wxpython notebook oddness

2009-04-27 Thread Gabriel Genellina
En Thu, 23 Apr 2009 16:44:25 -0300, Lawson English   
escribió:



Can anyone tell me why these two behave differfently?

http://pastebin.com/m57bee079 vs  http://pastebin.com/m3c044b29


The code is so different that I don't see why they should behave  
similarly...
Please strip it down to the bare minimum showing the discrepancy (and tell  
us *what* you see and what you expect)


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: ActiveState Komodo Edit?

2009-04-27 Thread Trent Mick

If you make line numbers visible (View -> View Line Numbers) then
you can do what you want in the line numbers gutter.


I am using the free editor-only Komodo Edit. Apparently that does not
work here. 


I believe it was a recent change. What version are you using? You could 
try the latest nightly build:

  http://downloads.activestate.com/Komodo/nightly/

Cheers,
Trent

--
Trent Mick
trentm at activestate.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: getattr on a function

2009-04-27 Thread Terry Reedy

Mr SZ wrote:

Hi all,

Is it possible to call functions using getattr. I have written a simple script 
with functions that call either SSL, TLS or plain functionality.

something like:
def func():
  ...

def funcSSL():
  ...

def funcTLS():


funcs = {'none':func, 'SSL':funcSSL, 'TLS':funcTLS}
...
cryptfunc = funcs[  ]


  ...

Now, based on my args I would like to call either one of them. In my case, I can't 
seem to figure out what my object would be when I call getattr(object, 
'func'+) !

" life isn't heavy enough,it flies away and floats far above action"


  Enjoy a safer web experience. Upgrade to the new Internet Explorer 8 
optimised for Yahoo!7. Get it now.
--
http://mail.python.org/mailman/listinfo/python-list



--
http://mail.python.org/mailman/listinfo/python-list


Re: wxpython notebook oddness

2009-04-27 Thread Mike Driscoll
On Apr 27, 1:50 pm, "Gabriel Genellina" 
wrote:
> En Thu, 23 Apr 2009 16:44:25 -0300, Lawson English   
> escribió:
>
> > Can anyone tell me why these two behave differfently?
>
> >http://pastebin.com/m57bee079vs  http://pastebin.com/m3c044b29
>
> The code is so different that I don't see why they should behave  
> similarly...
> Please strip it down to the bare minimum showing the discrepancy (and tell  
> us *what* you see and what you expect)
>
> --
> Gabriel Genellina

Just ignore him. He re-posted to the wxPython list and they seem to
have him straightened out now.

Mike
--
http://mail.python.org/mailman/listinfo/python-list


PyGame font issues

2009-04-27 Thread Peter Chant
Chaps,

I have the following code:

if pygame.font:
font = pygame.font.Font(None, 36)
#font = pygame.font.Font('liberationserif',36)
text = font.render("Esc to quit.", 1, (10, 10, 10))
textpos = text.get_rect()
textpos.centerx = background.get_rect().centerx
background.blit(text, textpos)

but I get the error:

Traceback (most recent call last):
  File "g6.py", line 77, in 
font = pygame.font.Font(None, 36)
RuntimeError: default font not found 'freesansbold.ttf'
bash-3.1$  

Now swapping the comments on the font= lines to use liberationserif which
definitely is on my system I get a similar fault.  Any suggestions on a
remidy?

-- 
http://www.petezilla.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: python list handling and Lisp list handling

2009-04-27 Thread Daniel Stutzbach
On Fri, Apr 24, 2009 at 10:19 AM, Mark Tarver wrote:

> but also says that their representation is implementation dependent.
> As far as I see this should mean that element access in Python should
> run in constant time.  Now if so this is a boon, because generally
>

When I first learned Python, I too was confused by the fact that Python
lists are actually arrays (or vectors) under-the-hood, and it was some time
before I learned that element access is fast (O(1)) but inserts, deletes,
and taking a sublist are slow (O(n)).

Much later, I went on to write a drop-in replacement type called the "blist"
that has the same methods as a Python list, but has better asymptotic
performance for many operations.  That way I can write use the list in the
most natural way without having to worry about accidentally hitting a O(n)
method.

http://pypi.python.org/pypi/blist/

--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC 
--
http://mail.python.org/mailman/listinfo/python-list


Re: is PyCodec_Encode API able to change encoding fron UCS-2 to UCS-4

2009-04-27 Thread Gabriel Genellina

En Mon, 27 Apr 2009 08:56:44 -0300, rahul  escribió:


is this generic API can be use to change ucs-2 to ucs-4
PyObject *  PyCodec_Encode(
   PyObject *object,
   const char *encoding,
   const char *errors
   );

if yes than what is the format of denoting ucs-4, because i try to do
that but all times i got segmentation fault, i used "ucs-4-le" for
little endian system and "ucs-4-be"  for big endian system to set
ucs-4 encoding.


The PyCodec_XXX functions seem to be undocumented - I don't know if this  
is on purpose or not. Anyway, I'd use the str/unicode methods:


PyObject* u = PyString_AsDecodedObject(some_string_in_utf16, "utf-16",  
NULL);

// don't forget to check for errors
PyObject* s = PyUnicode_AsEncodedString(u, "utf-32", NULL);
// don't forget to check for errors and decref u

Python 2.6 provides some convenience functions, like PyUnicode_DecodeUTF16  
and PyUnicode_EncodeUTF32


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: is PyCodec_Encode API able to change encoding fron UCS-2 to UCS-4

2009-04-27 Thread Gabriel Genellina

En Mon, 27 Apr 2009 08:56:44 -0300, rahul  escribió:


is this generic API can be use to change ucs-2 to ucs-4


I forget to comment on UCS-2 and UCS-4. Python does not support them  
directly; use utf-16 and utf-32 instead. If you start with an encoded  
string in UCS-2, the differences are irrelevant.


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Cannot find text in *.py files with Windows Explorer?

2009-04-27 Thread Terry Reedy

John Doe wrote:

Terry Reedy  wrote:

John Doe wrote:

John Doe  wrote:

...


Another file manager, FreeCommander, does find text in Python
files. 

However... It does not have Undo! Potentially risky.

Undo is an editor function.  I do not believe Windows Explore has
Undo either.


Besides Undo... editing functions like copy, paste, and move are all 
included in a file manager. You might not need that (Undo) safety 
feature... then again, some users think they do not need to keep a 
removable media backup copy of important files from their hard drive 
either.


Undo and other editing functions are part of a file manager. And Yes, 
Windows Explorer does include Undo. 


I learn something new.  In my WinXP, I found that Explorer has 'Undo 
Move' (good to learn actually, for when I drop a file in the wrong 
place), which also undoes normal delete (move to Recycle Bin) and which 
even 'undoes' copy by offering to move copy to recycle bin.


A file manager is too powerful to
be without Undo, unless maybe it prompts the user every time 
files/folders are moved or deleted. 


Explorer prompts both for Recycle-move and perma-delete.

Many have complained, but for some reason the author of FreeCommander 
does not care about that.


So I agree, better to reconfigure Windows search to look in .py files.

--
http://mail.python.org/mailman/listinfo/python-list


SSL Server side Client Certficate Verification in M2Crypto

2009-04-27 Thread Karthik
Hi,

 I have a small problem using the M2Crypto for SSL certificate verification.
I have a client and a server who wants to get the certificates verified by
the other in order start the communication. I am able to get the server
certificate verified by the client but not the client certificate in the
server.

I have attached the code which I use for this. Kindly tell me where I had
gone wrong.

I would appreciate a quick reply since I have not been able to make progress
in my project due to this problem.


I am using Python 2.6.1 version in Ubuntu 8.10. I have the OpenSSL version
0.9.8 and SWIG 1.33.
The M2Crypto I am using is 0.18.

I am also using my own CA to sign the certificates. The CA certificates are
available with both the server and the client.

Please let me know if you require additional information on this.

Thanks
Karthik
import select
import socket
import sys
import string
import M2Crypto

HOST = "127.0.0.1"
PORT = 5050
BACKLOG = 5
BUFF_SIZE = 1024

from M2Crypto import SSL


class client:

	def run(self):
		con = SSL.Context('tlsv1')

		#con.load_verify_locations('cacert.pem','/home/kchandr1/Desktop/sc/')
		##con.load_verify_locations('cacert.pem')
		#con.set_verify(SSL.verify_peer | SSL.verify_fail_if_no_peer_cert, depth = 9)
		con.load_client_ca('cacert.pem')
		con.load_cert(certfile = "client_crt.pem",keyfile = "client_key.pem")
		con.set_client_CA_list_from_file('cacert.pem')

		c= SSL.Connection(con)
		c.connect((HOST,5050))
		if c.get_peer_cert() is not None:
			print "Server Certificate verified"
			print c.get_verify_result()
			print c.get_peer_cert()
			con.load_client_ca('cacert.pem')
			con.load_cert(certfile = "client_crt.pem",keyfile = "client_key.pem")
		else:
			print "CLIENT: Not able to get certificate"
			sys.exit()

		data = raw_input("Enter")
		while data:
			c.send(data)
			data = raw_input("Enter to pass to server")
		c.close()


if __name__ == "__main__":
client1 = client()
try:

	client1.run()

except KeyboardInterrupt:
print "Keyboard Interrupt recieved"
s.close_socket()



import select
import socket
import sys
import string

HOST = "127.0.0.1"
PORT = 5050
BACKLOG = 5
BUFF_SIZE = 1024

from M2Crypto import SSL

class server:
	
	def run(self):

		con = SSL.Context('tlsv1')
		con.load_client_ca('cacert.pem')
		con.load_cert(certfile = "server_crt.pem",keyfile = "server_key.pem")
		con.load_verify_locations('cacert.pem')
		#con.set_verify(SSL.verify_peer | SSL.verify_fail_if_no_peer_cert, depth = 9)

			
		bindsocket = SSL.Connection(con)
		bindsocket.bind((HOST,PORT))
		bindsocket.listen(BACKLOG)
		print "waiting for connection"

		(connectsocket, fromaddress) = bindsocket.accept()
		c= SSL.Connection(con)

		if c.get_peer_cert() is not None:
			print "Client Certificate verified"
			print c.get_verify_result()
		else:
			print "Server: Not able to get certificate"
			print c.get_verify_result()
			print c.get_peer_cert()
			sys.exit()

		data = connectsocket.read()
		while data:
			print data
			data = connectsocket.read()
			connectsocket.write('200 OK\r\n\r\n')

		connectsocket.close()
		bindsocket.close()
		
		
if __name__ == "__main__":
s = server()
try:
s.run()
except KeyboardInterrupt:
print "Keyboard Interrupt recieved"
s.close_socket()



--
http://mail.python.org/mailman/listinfo/python-list


Re: Cannot find text in *.py files with Windows Explorer?

2009-04-27 Thread John Doe
Terry Reedy  wrote:
> John Doe wrote:

...

>> Windows Explorer does include Undo. 
> 
> I learn something new.  In my WinXP, I found that Explorer has 'Undo 
> Move' (good to learn actually, for when I drop a file in the wrong 
> place), 

Yup!

FWIW...
I enable the Windows Explorer status bar here. 
Then, doing 
File -- Undo (without clicking) 
and hovering the pointer over "Undo" shows on the status bar the last 
undoable action, if any. That allows me to see what files were involved 
and where the files went.
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: a metacomment on feedback comments

2009-04-27 Thread Aaron Watters
Regarding feedback about
WHIFF -- WSGI/HTTP Integrated Filesystems Frames

On Apr 23, 3:43 pm, Aaron Watters  wrote:
> On Apr 23, 11:54 am, Johannes Bauer  wrote:
>
> > To sum it up, I think it's a neat idea, but it's not really intuitive.
> > After being quite startled at first it got better after I read the "why
> > it's cool" page.
>
> Thanks for taking the time to check it out and comment, Johannes.
> I think you bring up a very good point --
> some of directive names are confusing.  

In retrospect the names were more than confusing.  They were
simply awful.   Thanks to Johannes, Drew and others I decided
to rename the directives:

"use-url" becomes "include",
"use-section" becomes "use",
"bind-section" becomes "reuse",
"bind-url" becomes "use-include",
"section" becomes "using",
"parameter" becomes "require"

These names are much less stupid (except for
use-include, but I couldn't come up with anything
better...).

Thanks Johannes and Drew!  There is a new release
with the new directive names linked from

  http://whiff.sourceforge.net

(What was I thinking?)

   -- Aaron Watters

===
KIDS MAKE NUTRITIOUS SNACKS
  (A real life newspaper headline)
--
http://mail.python.org/mailman/listinfo/python-list


Re: pyflakes, pylint, pychecker - and other tools

2009-04-27 Thread Esmail

Zooko O'Whielacronx wrote:
I like pyflakes.  I haven't tried the others.  I made a setuptools 
plugin named "setuptools_pyflakes".  If you install that package, then 
"python ./setup.py flakes" runs pyflakes on your package.


Regards,


Thanks Zooko

I decided to give all of them a try :-)

Esmail

--
http://mail.python.org/mailman/listinfo/python-list


Re: Thread-killing, round 666 (was Re: Lisp mentality vs. Python mentality)

2009-04-27 Thread David Bolen
Vsevolod  writes:

> "This should be used with caution: it is implementation-defined
> whether the thread runs cleanup forms or releases its locks first."
> This doesn't mean deprecated. It means: implementation-dependent. For
> example in SBCL: "Terminate the thread identified by thread, by
> causing it to run sb-ext:quit - the usual cleanup forms will be
> evaluated". And it works fine.

I'm curious - do you know what happens if threading is implemented as
a native OS thread and it's stuck in an I/O operation that is blocked?
How does the Lisp interpreter/runtime gain control again in order to
execute the specified function?  I guess on many POSIX-ish
environments, internally generating a SIGALRM to interrupt a system
operation might work, but it would likely have portability problems.

Or is that combination (native OS thread and/or externally blocking
I/O) prevented by the runtime somehow (perhaps by internally polling
what appears to code as blocking I/O)?  But surely if there's an
access to OS routines, the risk of blocking must be present?

That scenario is really the only rationale use case I've run into for
wanting to kill a thread, since in other cases the thread can be
monitoring for an application defined way to shut down.

-- David
--
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamically fill prepared (PDF?) forms

2009-04-27 Thread Alia K
pom wrote:
> So I want to create PDF output based on an external layout file.

You can allow for a transformation file which is read by your program
to change the layout of the output. Think templates.

AK


--
http://mail.python.org/mailman/listinfo/python-list


Re: Thread-killing, round 666 (was Re: Lisp mentality vs. Python mentality)

2009-04-27 Thread Paul Rubin
David Bolen  writes:
> I'm curious - do you know what happens if threading is implemented as
> a native OS thread and it's stuck in an I/O operation that is blocked?
> How does the Lisp interpreter/runtime gain control again in order to
> execute the specified function?  I guess on many POSIX-ish
> environments, internally generating a SIGALRM to interrupt a system
> operation might work, but it would likely have portability problems.

Someone wrote a paper proposing some Python language extensions to
support asynchronous exceptions in Python threads.  I don't have the
url handy but you can probably search for it.  
--
http://mail.python.org/mailman/listinfo/python-list


Re: CSV performance

2009-04-27 Thread dean
On Mon, 27 Apr 2009 04:22:24 -0700 (PDT), psaff...@googlemail.com wrote:

> I'm using the CSV library to process a large amount of data - 28
> files, each of 130MB. Just reading in the data from one file and
> filing it into very simple data structures (numpy arrays and a
> cstringio) takes around 10 seconds. If I just slurp one file into a
> string, it only takes about a second, so I/O is not the bottleneck. Is
> it really taking 9 seconds just to split the lines and set the
> variables?

I assume you're reading a 130 MB text file in 1 second only after OS
already cashed it, so you're not really measuring disk I/O at all.

Parsing a 130 MB text file will take considerable time no matter what.
Perhaps you should consider using a database instead of CSV.
--
http://mail.python.org/mailman/listinfo/python-list


Light (general) Inter-Process Mutex/Wait/Notify Synchronization?

2009-04-27 Thread Gunter Henriksen
I am interested in the lightest mechanism to use
in a Python application for mutex/wait/notify
between processes, one of which may be a program
which does not have a shared ancestral benefactor,
or may not be a Python program at all.

I would ideally like to have something which does
not need to make a system call in an uncontended
case for the mutex.  In C on Linux I would use mmap
to get shared memory, then pthread_cond_wait with
a cond/mutex which has the PTHREAD_PROCESS_SHARED
attribute set.  For pthread_cond_wait, it would of
course be fine to make a system call.

I am familiar with the "multiprocessing" package for
the case of a closely related set of Python programs.
I am looking for something where the other side is
not a Python application using "multiprocessing".

A thin layer over pthreads would be nice, or which
is using POSIX semaphores/queues would be ok.  I
can use mmap for shared memory; that is not problem.
The synchronization is where I need help.
--
http://mail.python.org/mailman/listinfo/python-list


Get objects from ZODB into MySQL

2009-04-27 Thread TheIvIaxx
Hello, I have searched for some solution to getting the object data
from a ZODB Data.fs file into something i can work with for MySQL.  So
far, no such luck.  I can open the DB and poke around, but im not sure
where or what to even poke :)

It was a simple plone site, with mainly Pages/Documents (the basic
content type).  I would imagine getting the object information into
some sort of csv or txt format would be easy.  I can't really find
anything in the ZMI that would do what i need either.

Any ideas on this?  Where in the DB are these objects stored and how
to retrieve them?

Thanks
--
http://mail.python.org/mailman/listinfo/python-list


Re: Get objects from ZODB into MySQL

2009-04-27 Thread Diez B. Roggisch

TheIvIaxx schrieb:

Hello, I have searched for some solution to getting the object data
from a ZODB Data.fs file into something i can work with for MySQL.  So
far, no such luck.  I can open the DB and poke around, but im not sure
where or what to even poke :)

It was a simple plone site, with mainly Pages/Documents (the basic
content type).  I would imagine getting the object information into
some sort of csv or txt format would be easy.  I can't really find
anything in the ZMI that would do what i need either.

Any ideas on this?  Where in the DB are these objects stored and how
to retrieve them?


The ZODB is essentially a persisted object graph. Not more, not less. In 
other words: there is no way to extract any "raw" data, all are 
python-objects. To persist these, you need to write a serialization of 
these objects to something that you can process further. XML-pickling 
might be an option. Or you write some generic thing based on dir() or 
__dict__.


Diez
--
http://mail.python.org/mailman/listinfo/python-list


Re: Get objects from ZODB into MySQL

2009-04-27 Thread Gabriel Genellina
En Mon, 27 Apr 2009 19:13:39 -0300, TheIvIaxx   
escribió:



Hello, I have searched for some solution to getting the object data
from a ZODB Data.fs file into something i can work with for MySQL.  So
far, no such luck.  I can open the DB and poke around, but im not sure
where or what to even poke :)


Try Shane Hathaway's APE library [1]. Currently unmaintained, but if this  
is a one-shot project it may be useful.
[1] somewhere inside http://www.hathawaymix.org -- maybe  
http://hathawaymix.org/Software


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: mailbox.mbox.add() sets access time as well as modification time

2009-04-27 Thread Lawrence D'Oliveiro
In message , Aahz wrote:

> In article ,
> Lawrence D'Oliveiro   wrote:
>>
>>It's only in the proprietary-software world that we need to worry about
>>backward compatibility with old, obsolete software that the vendors
>>cannot or will not fix. In the Free Software world, we fix the software
>>to bring it up to date.
> 
> Are you volunteering to maintain trn3.6?

Either there are enough people using it to care about it, in which case 
somebody in the community will fix it, it or there are not, in which case 
it's not worth bothering with.

--
http://mail.python.org/mailman/listinfo/python-list


Re: mailbox.mbox.add() sets access time as well as modification time

2009-04-27 Thread Lawrence D'Oliveiro
In message , Grant 
Edwards wrote:

> On 2009-04-26, Lawrence D'Oliveiro 
> wrote:
>
>> In message <_vqdnf6pny1gymzunz2dnuvz_qcdn...@posted.visi>, Grant Edwards
>> wrote:
>>
>>> ... if one didn't care about backwards-compatiblity with old e-mail
>>> apps, then one would use a less broken mailbox format like
>>> maildir.
>>
>> It's only in the proprietary-software world that we need to worry about
>> backward compatibility with old, obsolete software that the vendors
>> cannot or will not fix. In the Free Software world, we fix the software
>> to bring it up to date.
> 
> Who's "we"?  Are you volunteering to fix all of the MUAs and
> MTAs out there that have mbox code in them that do follow the
> rules to make them compatible with _one_ broken library module?

All the MUAs and MTAs I'm aware of that are worth bothering about have the 
option to support maildir format these days.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Light (general) Inter-Process Mutex/Wait/Notify Synchronization?

2009-04-27 Thread Lawrence D'Oliveiro
In message , Gunter 
Henriksen wrote:

> I would ideally like to have something which does
> not need to make a system call in an uncontended
> case for the mutex.

In Linux you could use a futex.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Get objects from ZODB into MySQL

2009-04-27 Thread William Heymann
On Monday 27 April 2009, TheIvIaxx wrote:
> Hello, I have searched for some solution to getting the object data
> from a ZODB Data.fs file into something i can work with for MySQL.  So
> far, no such luck.  I can open the DB and poke around, but im not sure
> where or what to even poke :)
>

Normally what you would do is make sure zope can connect to your mysql db. 
Then you write something like a catalog query in zope to find all the objects 
your interested in and you use a zsql method and insert each object into your 
database. So you need to find the attributes you care about in your zope 
objects. Usually this is fairly trivial to do 10-20 minutes or so.

The whole key is to do it from inside zope not from outside. Since from 
outside zope you can't really load the objects involved.


> It was a simple plone site, with mainly Pages/Documents (the basic
> content type).  I would imagine getting the object information into
> some sort of csv or txt format would be easy.  I can't really find
> anything in the ZMI that would do what i need either.
>

I doubt it would be easy to put it in some csv format without massive data 
loss. What do you do with images? files? workflow? document relationships? 
hierarchy? etc
--
http://mail.python.org/mailman/listinfo/python-list


Re: Light (general) Inter-Process Mutex/Wait/Notify Synchronization?

2009-04-27 Thread Paul Rubin
Gunter Henriksen  writes:
> A thin layer over pthreads would be nice, or which
> is using POSIX semaphores/queues would be ok.  I
> can use mmap for shared memory; that is not problem.
> The synchronization is where I need help.

Try this: http://nikitathespider.com/python/shm/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a maximum size to a Python program?

2009-04-27 Thread Paul Hemans
The reason I started down this path is that the program is grinding to a 
halt (my PC as well) and the only way to get it going again is:
>>>import gc
>>>gc.collect()
2524104

Memory used by the process is around 500MB, I have posted about this problem 
before on this newsgroup but I didn't get a resolution. So I was trying to 
separate the logic into different files and finish each one with 
gc.collect().
Sorry I didn't post the original problem as well but I really just wanted 
the thing to work and not cloud the issue again.
I have implemented your approach and the code is much cleaner (except for 
another problem that I have posted to sqlAlchemy). It doesn't solve my 
original problem with the memory, but I really need SOMETHING to work. So I 
will keep plodding away and then maybe move the XML processing to lxml and 
see if that resolves the memory problem.


"John Machin"  wrote in message 
news:3215638c-2408-4cf6-9321-f85f560e6...@u39g2000pru.googlegroups.com...
On Apr 27, 3:31 pm, "Paul Hemans"  wrote:
> Thanks John, I understand where you are coming from and will try and 
> digest
> it all. One problem though that I didn't mention in my original posting 
> was
> that the replication may only require updating one or more fields, that is 
> a
> problem with a generating a single SQL statement to cover all requests.

OK so you need TWO programs -- one tailored for initial loading of a
table, the other for subsequent updates. Still O(1) :-)

OR you could still do it in one, by using the prepared whole-row SQL
statement if appropriate, or building an SQL statement on the fly if
it's an update.

> I am
> having a look at eval and exec

WRONG WAY
GO BACK

> to see if they will give me a little more
> flexibility in runtime generation of the code.

And another thing that you didn't mention was that you are using
SQLAlchemy -- perhaps you might like to ask your question on that
package's forum ... including a few more facts than heretofore :-)

HTH
John 


--
http://mail.python.org/mailman/listinfo/python-list


can't use "glog" to find the path with square bracket

2009-04-27 Thread winterTTr
I want to list the file with glob .
The path( which is a directory ) is contain square bracket as "[ab]
xxx"
.  However , i can't find how to do it rightly with glob .

with the coding :

{{{
import glob
glob.glob('[ab]xxx' )
}}}

and with the path "[ab]xxx" really exits.
result : []

Is there a way to do it rightly ?

And i know the fact that  [ is a special character for glob().
But how can i escape it when using glob?

PS:
 Python : 2.5
 Platform : Win XP
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a maximum size to a Python program?

2009-04-27 Thread andrew cooke

not sure i've read all the posts on this, and i don't fully understand the
problem, but someone's mentioned sqlalchemy, so here's my experience with
that and large updates using mapped objects.

1 - don't commit each object as you modify it.  instead, process a whole
pile in memory and then (perhaps every 10,000 - when your memory is about
to run out and start paging) flush the session.  you'll find that the
memory use is very predictable - it ramps up as objects are cached and
then drops back down to the original level once they're sent to the
database.

2 - various sql related commands in sqlalchemy will take lists rather than
single values, and process all elements in the list in one "chunk".  this
is much more efficient.  using sql directly is faster and uses lest memory
than using mapped objects (the nice thing about sqlalchemy is that you can
use sql directly when it's the best solution, and mapped objects when they
are more useful).

these are both kind-of obvious, but that's all i needed to handle fairly
large data volumes with sqlalchemy.

andrew


Carbon Man wrote:
> I have a program that is generated from a generic process. It's job is to
> check to see whether records (replicated from another system) exist in a
> local table, and if it doesn't, to add them. I have 1 of these programs
> for
> every table in the database. Everything works well until I do the postcode
> table. The generated code is 5MB for a system with no current data.
> Normally
> the file would not be this big as only the changes are copied over. Python
> just quits, I have tried stepping through the code in the debugger but it
> doesn't even start.
> I am thinking that dynamically generating the programs to run might not be
> such a good idea. It would be a shame to drop it because the system needs
> to
> be generic and it runs from an XML file so the resulting code could be
> pretty complex, and I am new to Python. The program did generate a pyc so
> it
> was able to compile.
> Thoughts anyone?
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


--
http://mail.python.org/mailman/listinfo/python-list


Re: Light (general) Inter-Process Mutex/Wait/Notify Synchronization?

2009-04-27 Thread Paul Rubin
Gunter Henriksen  writes:
> > Try this: http://nikitathespider.com/python/shm/
> 
> I took a look at that (especially the posix_ipc at
> http://semanchuk.com/philip/posix_ipc/).  I am hoping not to plug
> something underneath the Python VM; I would rather use a socket, or
> use signals. 

I'm not sure what you mean.  It's just an extension module that you'd
import like any of the stdlib modules.  Certainly anything involving
sockets or signals is going to be a lot slower.
--
http://mail.python.org/mailman/listinfo/python-list


How can I get Tkinter to work in Python? (I tried many things)

2009-04-27 Thread tomzam
I am trying to get Tkinter to work with my Python build.
I've scoured usenet(comp.lang.Python) and google and there's
information that's helpful but I just can't seam to get it completely
right. I tried many of the suggestion, but nothing seems to work
My setup is Fedora Core 6 [my yum is also broken. (sigh. yes, I know
I should upgrade)]
I've download Tcl/Tk from Active State and installed it here:
/usr/ActiveTcl-8.5
My python to build is in this directory:
/home/tomzam/mylib6/Python-2.6.2
I removed the comment symbol (#)  from the line:
  _tkinter _tkinter.c tkappinit.c -DWITH_APPINIT \
in the Modules/Setup
so the lines in the Setup file look like this:

# *** Always uncomment this (leave the leading underscore in!):
  _tkinter _tkinter.c tkappinit.c -DWITH_APPINIT \
# *** Uncomment and edit to reflect where your Tcl/Tk libraries are:
-L/usr/ActiveTcl-8.5/lib/tk8.5 \
# *** Uncomment and edit to reflect where your Tcl/Tk headers are:
-I/usr/ActiveTcl-8.5/include/tcl8.5 \
when I run ./configure in /home/tomzam/mylib6/Python-2.6.2 everything
looks
right but then I try running  make in /home/tomzam/mylib6/Python-2.6.2

There are errors, but since there is many of them:
here is a cut out of the _tkinter errors:

libpython2.6.a(_tkinter.o): In function `Tkapp_CallProc':
/home/tomzam/mylib6/Python-2.6.2/./Modules/_tkinter.c:1263: undefined
reference to `Tcl_MutexLock'
/home/tomzam/mylib6/Python-2.6.2/./Modules/_tkinter.c:1264: undefined
reference to `Tcl_ConditionNotify'
/home/tomzam/mylib6/Python-2.6.2/./Modules/_tkinter.c:1265: undefined
reference to `Tcl_MutexUnlock'
/home/tomzam/mylib6/Python-2.6.2/./Modules/_tkinter.c:1251: undefined
reference to `Tcl_GetStringResult'
libpython2.6.a(_tkinter.o): In function `Tkapp_CallDeallocArgs':
/home/tomzam/mylib6/Python-2.6.2/./Modules/_tkinter.c:1123: undefined
reference to `Tcl_Free'
libpython2.6.a(tkappinit.o): In function `Tcl_AppInit':
/home/tomzam/mylib6/Python-2.6.2/./Modules/tkappinit.c:48: undefined
reference to `Tcl_Init'
/home/tomzam/mylib6/Python-2.6.2/./Modules/tkappinit.c:77: undefined
reference to `Tcl_GetVar'
/home/tomzam/mylib6/Python-2.6.2/./Modules/tkappinit.c:81: undefined
reference to `Tk_Init'
/home/tomzam/mylib6/Python-2.6.2/./Modules/tkappinit.c:84: undefined
reference to `Tk_MainWindow'
/home/tomzam/mylib6/Python-2.6.2/./Modules/tkappinit.c:81: undefined
reference to `Tk_Init'
collect2: ld returned 1 exit status
make: *** [python] Error 1

But since they are all undefined references - I feel I'm pretty close
to a solution.

Can you help me the rest of the way?
I'm trying to make tkinter work with my local Python install,
 any help will be appreciated!

Thank in advance,
-Tom Z
--
http://mail.python.org/mailman/listinfo/python-list


Re: Light (general) Inter-Process Mutex/Wait/Notify Synchronization?

2009-04-27 Thread Gunter Henriksen
> Try this: http://nikitathespider.com/python/shm/

I took a look at that (especially the posix_ipc at
http://semanchuk.com/philip/posix_ipc/).  I am hoping
not to plug something underneath the Python VM; I
would rather use a socket, or use signals.  If I were
to use a C library, I imagine I would just go with a
thin layer on top of pthread_*, but I think I will
prefer something which uses system calls and is
bundled with Python, slow as that approach may be.
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >