lmlx & & caracter

2009-10-27 Thread Toff
hello

i can't parse a file with lxml



  
 
 
  http://download.mozilla.org/?
product=firefox-3.5&os=win&lang=fr"  />
  
  
=

i know that & is a special caracter in xml

but how to parse the file

here is what i do :
filename = "file.xml"
xml = etree.parse(filename)
xml = ET.parse(filename)
for group in xml.getiterator('package'):
print group.get('id')


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


Re: How to know locals of script without running it

2009-10-27 Thread Johan Grönqvist

Nadav Chernin skrev:

Is there a way to know locals of the script without running it?


As I interpret the question, I believe there is. I think Pylint does 
what you want. I have no idea how it does it, or how certain it can be 
to find all locals, but it may give you a place to start looking.


Pylint homepage: 

/ johan

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


Re: Is there a command that returns the number of substrings in a string?

2009-10-27 Thread Gerard Flanagan

alex23 wrote:

Gerard Flanagan  wrote:

def count(text, *args):


Other than the ability to handle multiple substrings, you do realise
you've effectively duplicated str.count()?


I realise that calling this count function with a single argument would 
be functionally identical to calling str.count(), yes. But I can imagine 
the situation of wanting to find multiple (disjoint) substrings. Is 
there a reason for preferring multiple calls to str.count() in such a 
case? Or is there a more obvious approach?


> Gerard Flanagan  wrote:
> re.findall?

Forget that, that was stupid.



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


Re: Problem embedding Python.

2009-10-27 Thread Gabriel Genellina
En Tue, 27 Oct 2009 03:25:54 -0300, Brandon Keown  
 escribió:



I am going to try to embed python in an application, but in simple
testing, I could not get it to work.  The following code seems like it
should work, but it crashes, and I have tried several things.  What
could I be doing wrong?

#include 

int main(int argc, char* argv[])
{
FILE* fp = fopen("test.py","r");
Py_Initialize();
PyRun_SimpleFile(fp,"test.py");
Py_Finalize();
return 0;
}


Crashes, how? Try running inside a debugger to see where it crashes, or at  
least put a few printf.
You didn't test for the fopen result; are you sure "test.py" exists in the  
current directory at the time you run it?


--
Gabriel Genellina

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


how to modify row content of file in python?

2009-10-27 Thread holmes86
hi,everyone

Is there function of modify row content in python? just like 'sed' in
shell,thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2009-10-27 Thread Steven D'Aprano
On Mon, 26 Oct 2009 09:51:11 -0700, Anh Hai Trinh wrote:

> I've written something that is better than you could've imagine.
> 
> Get it here: 
> 
> It works with anything iterable, no need to alter anything.


Looks nice. In my Copious Spare Time I will try to look at it.


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


Re: lmlx & & caracter

2009-10-27 Thread Christian Heimes
Toff wrote:
> hello
> 
> i can't parse a file with lxml
> 
> 
> 
>   
>  
>  
>   http://download.mozilla.org/?
> product=firefox-3.5&os=win&lang=fr"  />
>   
>   
> =
> 
> i know that & is a special caracter in xml

Because & has a special meaning in XML you have to quote a literal & as
&

Christian

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


Re: Is there a command that returns the number of substrings in a string?

2009-10-27 Thread Gabriel Genellina
En Tue, 27 Oct 2009 04:31:22 -0300, Gerard Flanagan   
escribió:



alex23 wrote:

Gerard Flanagan  wrote:

def count(text, *args):

 Other than the ability to handle multiple substrings, you do realise
you've effectively duplicated str.count()?


I realise that calling this count function with a single argument would  
be functionally identical to calling str.count(), yes. But I can imagine  
the situation of wanting to find multiple (disjoint) substrings. Is  
there a reason for preferring multiple calls to str.count() in such a  
case? Or is there a more obvious approach?


There is a more efficient algorithm (Aho-Corasick) which computes all  
occurences of a set of substrings inside a given string at once. It  
*should* be faster than repeatly calling str.find for every substring, and  
faster than using regular expressions too. (note that you get not only the  
count of occurences, but their positions too).
I've seen a couple implementations for Python; if they're *actually*  
faster is to be determined...


--
Gabriel Genellina

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


Re: handling PAMIE and lxml

2009-10-27 Thread Stefan Behnel
elca, 26.10.2009 23:15:
> im not familiar with python,currently im learning python.

Note that there is also a separate list that is specifically dedicated to
beginners: the Python tutor mailing list.

But the best advice I can give is to start reading documentation. Maybe
start with this one:

http://www.catb.org/~esr/faqs/smart-questions.html

Really helps in solving problems faster.


> but where is end of learning pyton? there is some end of learning python or
> programming? 

No. If there was, the life of an average programmer would be so boring that
few people would really want to do it.


> and what is 'wtf' ? :)

Why not ask your favourite search engine? It'll point you to tons of pages
like this that help out:

http://www.webacronyms.com/
http://acronyms.silmaril.ie/cgi-bin/uncgi/acronyms

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


Re: lmlx & & caracter

2009-10-27 Thread Stefan Behnel
Toff, 27.10.2009 09:15:
> but does my download url still allways works with & replace by $amp;

Sorry, my English fails to parse that. If that was a question, could you
rephrase it, please?

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


Re: lmlx & & caracter

2009-10-27 Thread Stefan Behnel
Toff, 27.10.2009 09:15:
> On 27 oct, 09:03, Christian Heimes  wrote:
>> Toff wrote:
>>> hello
>>> i can't parse a file with lxml
>>> 
>>>   
>>>  
>>>  
>>>   http://download.mozilla.org/?
>>> product=firefox-3.5&os=win&lang=fr"  />
>>>   
>>>   
>>> =
>>> i know that & is a special caracter in xml
>> Because & has a special meaning in XML you have to quote a literal & as
>> &
> 
> but does my download url still allways works with & replace by $amp;

In case you want to know if the URL keeps working if you replace '&' by
'&' in your XML file, then the answer is that it will actually /start/
working that way, because it will not work the way you show above. An XML
parser will return the URL as expected.

Note that it's also best to use an XML toolkit to actually generate XML, in
case you wrote the above file programmatically.

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


Re: Is there a command that returns the number of substrings in a string?

2009-10-27 Thread alex23
Gerard Flanagan  wrote:
> I realise that calling this count function with a single argument would
> be functionally identical to calling str.count(), yes. But I can imagine
> the situation of wanting to find multiple (disjoint) substrings. Is
> there a reason for preferring multiple calls to str.count() in such a
> case? Or is there a more obvious approach?

No, I totally missed that it was counting disjoint substrings :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to get os.system () call to cooperate on Windows

2009-10-27 Thread Anthra Norell

Kushal Kumaran wrote:

On Tue, Oct 27, 2009 at 2:04 AM, Anthra Norell  wrote:
  



No, I didn't. There's a number of modules I know by name only and shutils
was one of them. A quick peek confirmed that it is exactly what I am looking
for. Thank you very much for the advice.




Then Doug Hellmann's PyMOTW is for you. http://blog.doughellmann.com/

  


Thanks for your tip too. It doesn't directly relate to my question, but 
points to a source of welcome clarifications.


Frederic

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


Re: lmlx & & caracter

2009-10-27 Thread Toff
sorry for my english
thanks again for your answer ;)


i did that 

o = open("output.txt","w")
data = open(filename).read()
o.write( re.sub('&(?!amp;|quot;|nbsp;|gt;|lt;|laquo;|
raquo;|copy;|reg;|bul;|rsquo;)', '&', data) )
o.close()
shutil.move
("output.txt",filename)
xml = etree.parse(filename)
xml = ET.parse(filename)

it's dirty but works



On 27 oct, 09:36, Stefan Behnel  wrote:
> Toff, 27.10.2009 09:15:
>
>
>
> > On 27 oct, 09:03, Christian Heimes  wrote:
> >> Toff wrote:
> >>> hello
> >>> i can't parse a file with lxml
> >>> 
> >>>   
> >>>  
> >>>  
> >>>   http://download.mozilla.org/?
> >>> product=firefox-3.5&os=win&lang=fr"  />
> >>>   
> >>>   
> >>> =
> >>> i know that & is a special caracter in xml
> >> Because & has a special meaning in XML you have to quote a literal & as
> >> &
>
> > but does my download url still allways works with & replace by $amp;
>
> In case you want to know if the URL keeps working if you replace '&' by
> '&' in your XML file, then the answer is that it will actually /start/
> working that way, because it will not work the way you show above. An XML
> parser will return the URL as expected.
>
> Note that it's also best to use an XML toolkit to actually generate XML, in
> case you wrote the above file programmatically.
>
> Stefan

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


Re: Problem embedding Python.

2009-10-27 Thread Brandon Keown
On Oct 27, 2:47 am, "Gabriel Genellina" 
wrote:
>
> Crashes, how? Try running inside a debugger to see where it crashes, or at  
> least put a few printf.
> You didn't test for the fopen result; are you sure "test.py" exists in the  
> current directory at the time you run it?
>
> --
> Gabriel Genellina

Ok, so I assumed that the file, if supplied without a path, would use
current working directory, which was evidently a false assumption.  I
put in an if statement to check to see if the pointer was null which
it was.  So I fully qualified the path in the test file.  Now it
throws an unhandled exception when it goes to execute the line with
PyRun_SimpleFile.  The following code yields the errors after it.

#include 

int main(int argc, char* argv[])
{
FILE* fp = fopen("c:\\Patches\\Test\\Debug\\test.py","w");
if(fp == NULL)
printf("error");
Py_Initialize();
PyRun_SimpleFile(fp,"test.py");
Py_Finalize();
return 0;
}

"First-chance exception at 0x77d2dbba in Test.exe: 0xC005: Access
violation writing location 0x0014.
Unhandled exception at 0x77d2dbba in Test.exe: 0xC005: Access
violation writing location 0x0014.
First-chance exception at 0x77d2dbba in Test.exe: 0xC005: Access
violation writing location 0x0014.
Unhandled exception at 0x77d2dbba in Test.exe: 0xC005: Access
violation writing location 0x0014."

In the debug output.

This is the call stack (the first line is where execution halted).

Test.exe!main(int argc=1, char** argv=0x006d1b88)  Line 9 + 0x15 bytes
Test.exe!__tmainCRTStartup()  Line 586 + 0x19 bytes
Test.exe!mainCRTStartup()  Line 403

(There is more after this, but it goes back to system calls and
execution is halted here so I thought this was relevant).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to modify row content of file in python?

2009-10-27 Thread Gabriel Genellina
En Tue, 27 Oct 2009 05:50:47 -0300, Lutz Horn   
escribió:

* holmes86 [Tue, 27 Oct 2009 00:55:36 -0700]:



Is there function of modify row content in python? just like 'sed' in
shell,thanks


Sed doesn't actually modify the contents of a file. In normal operation
mode it reads from STDIN and writes to STDOUT. Some versions of sed
provide the -i option to

  edit files in place (makes backup if extension supplied)

You could program a similar behaviour in Python using the re module.


There is the fileinput module:
http://docs.python.org/library/fileinput.html

--
Gabriel Genellina

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


PSP problem showing images

2009-10-27 Thread Alfons Nonell-Canals
Hello,
I have experience working with Python an dnow I would like to use it for
web development. I worked with php from several years ago and I'm trying
to move to PSP. I have no problem runing some tests, implement an small
project with psp is pretty easy. But I have only one problem, me scrips
don't show any image.

I developed a script which generates some images (is a work about
Chemistry) and returns a page with some results and these images. When I
run the script from the web browser, "all" works fine: the images are
created, some other staff is calculated and the final page with the
results is fine except the images. It does not print the images! I chech
the paths and all is fine.

With it I thought tha maybe there is something wrong in the apache's
configuration. And I'm almost sure the problem is there because the
Handler used only manages .psp documents. I add some code to not apply
the Handler to .png but... help?

Do you have any idea/experience?

Below is the configuration of the host...


ServerAdmin [email protected]
ServerName  www.domain.com
ServerAlias domain.com

# Indexes + Directory Root.
DirectoryIndex index.psp
DocumentRoot /path/to/the/pages

AddHandler mod_python .psp
PythonHandler mod_python.psp
PythonDebug On

Sethandler None


 


# Logfiles
ErrorLog  /var/log/apache2/domain.com-error.log
CustomLog /var/log/apache2/domain.com-access.log combined



Thanks in advance!

Regards,
Alfons.


-- 

Alfons Nonell-Canals, PhD
Chemogenomics Lab
Research Group on Biomedical Informatics (GRIB) - IMIM/UPF
Barcelona Biomedical Research Park (PRBB)
C/ Doctor Aiguader, 88 - 08003 Barcelona 
[email protected] - http://cgl.imim.es
Tel. +34933160528
 
http://alfons.elmeuportal.cat
http://www.selenocisteina.info

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


Re: Problem embedding Python.

2009-10-27 Thread Brandon Keown
I found the problem.  Evidently as posted on a few other areas of the
internet, this is a common problem when trying to use compilers that
may have different type definitions for (FILE*).  Here is workable
solution:

#include 

int main(int argc, char* argv[])
{
PyObject* PyFileObject;
char* filename;
Py_Initialize();
filename = "c:\\Patches\\Test\\Debug\\test.py";
PyFileObject = PyFile_FromString(filename, "r");
PyRun_SimpleFile(PyFile_AsFile(PyFileObject), filename);
Py_Finalize();
return 0;
}
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lmlx & & caracter

2009-10-27 Thread Stefan Behnel
Toff, 27.10.2009 10:14:
> o = open("output.txt","w")
> data = open(filename).read()
> o.write( re.sub('&(?!amp;|quot;|nbsp;|gt;|lt;|laquo;|
> raquo;|copy;|reg;|bul;|rsquo;)', '&', data) )
> o.close()
> shutil.move
> ("output.txt",filename)
> xml = etree.parse(filename)
> xml = ET.parse(filename)

Absolutely no reason to write a file here. Use ET.fromstring().

And, just to repeat my question in other words: can't you just fix the
'XML' file before hand? I.e. is it a broken XML file coming from an outside
source that you cannot control, or did you create it yourself?

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


Re: a simple unicode question

2009-10-27 Thread Lie Ryan

Chris Jones wrote:

On Wed, Oct 21, 2009 at 12:35:11PM EDT, Nobody wrote:

[..]


Characters outside the 16-bit range aren't supported on all builds.
They won't be supported on most Windows builds, as Windows uses 16-bit
Unicode extensively:


I knew nothing about UTF-16 & friends before this thread.

Best part of Unicode is that there are multiple encodings, right? ;-)


No, the best part about Unicode is there is no encoding!

Unicode does not define any encoding; what it defines is code-points for 
characters which is not related to how characters are encoded in files 
or network transmission.

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


Re: PSP problem showing images

2009-10-27 Thread Lawrence D'Oliveiro
In message , Alfons 
Nonell-Canals wrote:

> I developed a script which generates some images (is a work about
> Chemistry) and returns a page with some results and these images. When I
> run the script from the web browser, "all" works fine: the images are
> created, some other staff is calculated and the final page with the
> results is fine except the images. It does not print the images! I chech
> the paths and all is fine.

Did you view source to check the URLs in the “” directives? 
Did you try copying and pasting the image URLs directly into new 
windows/tabs, to see if they came up or you got an error page instead?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PSP problem showing images

2009-10-27 Thread Alfons Nonell-Canals
Hi Lawrence,
Yes, I've tried it! I've saw the code, copyed the src path ans pasted
into the browser and it works. I think it not works only unther a psp
hostname/directory, for this reason I thought the problem is in the
apache2 (site) configuration pasted in my mail...

Thanks!
Alfons.



Lawrence D'Oliveiro wrote:
> In message , Alfons 
> Nonell-Canals wrote:
>
>   
>> I developed a script which generates some images (is a work about
>> Chemistry) and returns a page with some results and these images. When I
>> run the script from the web browser, "all" works fine: the images are
>> created, some other staff is calculated and the final page with the
>> results is fine except the images. It does not print the images! I chech
>> the paths and all is fine.
>> 
>
> Did you view source to check the URLs in the “” directives? 
> Did you try copying and pasting the image URLs directly into new 
> windows/tabs, to see if they came up or you got an error page instead?
>   

-- 

Alfons Nonell-Canals, PhD
Chemogenomics Lab
Research Group on Biomedical Informatics (GRIB) - IMIM/UPF
Barcelona Biomedical Research Park (PRBB)
C/ Doctor Aiguader, 88 - 08003 Barcelona 
[email protected] - http://cgl.imim.es
Tel. +34933160528
 
http://alfons.elmeuportal.cat
http://www.selenocisteina.info

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


Re: best vi / emacs python features

2009-10-27 Thread Lawrence D'Oliveiro
In message , Jean-Michel 
Pichavant wrote:

> Being a vi fan, I can just tell you that emacs is for loosers, and no
> one will dare to challenge this.

Is it better to be loose or tight?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SQL user function returning list for IN clause

2009-10-27 Thread Lawrence D'Oliveiro
In message , Felix wrote:

> I want to run a query like
> 
> select * from table a, table b where a.foo IN foobar(b.bar)
> 
> where foobar is a user function (registered by create_function in
> pysqlite3) returning a list of integers. However such functions can
> only return basic data types so the above is invalid. I am wondering
> what the best way around this is.

Is it feasible to iterate over the entire inner join of both tables?

for entry in iterator("select a.foo, b.bar ... from a, b") :
if foobarp(entry["a.foo"], entry["b.bar"]) :
 this is a combination I want ...

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


ftpilb.FTP.stor...() freeze mystery

2009-10-27 Thread Anthra Norell

Hi,
 I am trying to upload a bunch of web pages to a hosting service. I 
have a connected ftplib.FTP object and can upload files manually from an 
IDLE command line using the methods storlines () for html files and 
storbinary () for the pictures. So far no problem. In order to upload 
the whole set of files I wrote a loop that iterates through the file 
names and calls either of the stor... () methods as appropriate. The 
loop successfully uploads eight of some twenty files and then freezes. 
Ctrl-C doesn't unlock the freeze. I have to kill the IDLE window which 
raises a confirmation request "are you sure? The program is still 
running." Having no alternative I am sure. I open a new IDLE window and 
start over. Every retry fails the exact same way.
  My upload method with the loop has a preview mode. It goes through 
all the motions including opening and closing my source files but skips 
the stor... () methods and in addition displays all commands. The 
preview mode completes the iteration sequence and shows nothing unexpected.
  What could be the problem? I am totally 
fazed and will be most grateful for expert suggestions.


Frederic

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


Re: Why is python so sad?

2009-10-27 Thread Dotan Cohen
> Maybe we should change it to
>
> def ...(...(:
>     ...
>
> class ...(...(:

I disagree. It looks like one smiley is drooling into the other smiley's mouth.
Two smileys, one function? Yuk!

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: WHIFF += Mako & treeview & url rewrites

2009-10-27 Thread Paul Boddie
On 27 Okt, 03:49, Aaron Watters  wrote:
>
> WHIFF now includes components for
> implementing "tree views" for web navigation panes
> or other purposes, either using AJAX or frame
> reloads.  Try the GenBank demo at
>
> http://aaron.oirt.rutgers.edu/myapp/GenBankTree/index

This looks interesting, but when I have JavaScript switched off, I get
a big traceback page which indicates that the application doesn't
understand the normal link on each of the nodes of the tree. I imagine
that the ideas is to have the application functional with and without
JavaScript, which is a worthy objective forgotten by many Web
developers these days.

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


Re: Web development with Python 3.1

2009-10-27 Thread Alan Harris-Reid

Aaron Watters wrote:

On Oct 25, 7:52 pm, Alan Harris-Reid  wrote:
  

I am very much new to Python, and one of my first projects is a simple
data-based website. I am starting with Python 3.1 (I can hear many of
you shouting "don't - start with 2.6"), but as far as I can see, none of
the popular python-to-web frameworks (Django, CherryPy, web.py, etc.)
are Python3 compatible yet.

So, what can I use to start my web programming experience using 3.1?

Any help would be appreciated.

Alan



Don't. use python 2.6 with WHIFF :)
  http://aaron.oirt.rutgers.edu/myapp/GenBankTree/index
  http://whiff.sourceforge.net

-- Aaron Watters

Thanks for the advice

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


Re: ANN: WHIFF += Mako & treeview & url rewrites

2009-10-27 Thread Aaron Watters
On Oct 27, 7:04 am, Paul Boddie  wrote:
> On 27 Okt, 03:49, Aaron Watters  wrote:
>
>
>
> > WHIFF now includes components for
> > implementing "tree views" for web navigation panes
> > or other purposes, either using AJAX or frame
> > reloads.  Try the GenBank demo at
>
> >http://aaron.oirt.rutgers.edu/myapp/GenBankTree/index
>
> This looks interesting, but when I have JavaScript switched off, I get
> a big traceback page which indicates that the application doesn't
> understand the normal link on each of the nodes of the tree. I imagine
> that the ideas is to have the application functional with and without
> JavaScript, which is a worthy objective forgotten by many Web
> developers these days.
>
> Paul

That exact application

http://aaron.oirt.rutgers.edu/myapp/GenBankTree/index

cannot be implemented with javascript
turned off.  You can implement something
kinda similar... h

These days I would guess you are pretty
limited without javascript, no?  For example
I don't think the instructional support web
sites at Rutgers will work properly without
js.

By the way tracebacks are on for debugging
purposes, they can be turned off, of course.

  -- Aaron Watters
===
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: WHIFF += Mako & treeview & url rewrites

2009-10-27 Thread Aaron Watters
Paul Boddie wrote:
> On 27 Okt, 03:49, Aaron Watters  wrote:
...
> > http://aaron.oirt.rutgers.edu/myapp/GenBankTree/index
>
> This looks interesting, but when I have JavaScript switched off, I get
> a big traceback ...

I just tried it.  How do you get a traceback?  For me none of the
javascript links work: they just do nothing.
-- Aaron Watters

===
if you want a friend, get a dog.  --Truman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: WHIFF += Mako & treeview & url rewrites

2009-10-27 Thread alex23
Aaron Watters  wrote:
> I just tried it.  How do you get a traceback?  For me none of the
> javascript links work: they just do nothing.

I'm getting the same as Paul in Firefox 3.5.3 with javascript
disabled:

  Python 2.5: /
usr/local/apache2/bin/httpd
Tue Oct 27 07:56:50 2009

A problem occurred in a Python script. Here is the sequence of
function calls leading up to the error, in the order they occurred.
 /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
packages/whiff/middleware/displayTraceback.py in __call__
(self=, env={'DOCUMENT_ROOT': '/usr/local/apache2/htdocs',
'GATEWAY_INTERFACE': 'CGI/1.1', 'HTTP_ACCEPT': 'text/html,application/
xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_CHARSET':
'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'HTTP_ACCEPT_ENCODING':
'gzip,deflate', 'HTTP_ACCEPT_LANGUAGE': 'en-us,en;q=0.5',
'HTTP_CONNECTION': 'keep-alive', 'HTTP_HOST':
'aaron.oirt.rutgers.edu', 'HTTP_KEEP_ALIVE': '300', 'HTTP_REFERER':
'http://aaron.oirt.rutgers.edu/myapp/GenBankTree/index', ...},
start_response=)
   44 #pr "displayTraceback called for", page
   45 try:
   46 pageContentSequence = page(env, start_response)
   47 pageContentList = list(pageContentSequence)
   48 return pageContentList
...

If you need a full traceback, let me know.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: WHIFF += Mako & treeview & url rewrites

2009-10-27 Thread Aaron Watters
On Oct 27, 8:02 am, alex23  wrote:

> If you need a full traceback, let me know.

Well, yes, the bottom of the traceback would be more useful :).

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


RE: Web development with Python 3.1

2009-10-27 Thread Billy Earney
I would agree with Alan.  Most of the libraries you should use are
compatible with the 2.x series..  I still use versions 2.5 and 2.6 for all
development.

 

From: [email protected]
[mailto:[email protected]] On Behalf Of
Alan Harris-Reid
Sent: Tuesday, October 27, 2009 6:08 AM
To: Python List
Subject: Re: Web development with Python 3.1

 

Aaron Watters wrote: 

On Oct 25, 7:52 pm, Alan Harris-Reid  
 wrote:
  

I am very much new to Python, and one of my first projects is a simple
data-based website. I am starting with Python 3.1 (I can hear many of
you shouting "don't - start with 2.6"), but as far as I can see, none of
the popular python-to-web frameworks (Django, CherryPy, web.py, etc.)
are Python3 compatible yet.
 
So, what can I use to start my web programming experience using 3.1?
 
Any help would be appreciated.
 
Alan


 
Don't. use python 2.6 with WHIFF :)
  http://aaron.oirt.rutgers.edu/myapp/GenBankTree/index
  http://whiff.sourceforge.net
 
-- Aaron Watters

Thanks for the advice

Alan

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


Re: restriction on sum: intentional bug?

2009-10-27 Thread Steve
On Oct 17, 8:28 pm, Tim Chase  wrote:
> Christian Heimes wrote:
> > Alan G Isaac wrote:
> >> On 10/16/2009 5:03 PM, Christian Heimes wrote:
> >>> It's not going to happen.
> >> That's a prediction, not a justification.
>
> > It's not a prediction, it's a statement. It's not going to happend
> > because it violates Guido's gut feeling as well as the Zen of Python.
>
> I'm not sure how it violates ZoP...particularly
>
> Simple is better than complex.
>    [complex is special casing or explaining why there's an error]
> Special cases aren't special enough to break the rules.
>    [raising an error is a special case]
> Although practicality beats purity.
> In the face of ambiguity, refuse the temptation to guess.
>    [there's nothing ambiguous about sum() meaning "+"]
> If the implementation is easy to explain, it may be a good idea.
>    [sum(lst_of_strs) should do exactly what it says..."+" 'em]
>
> -tkc

Sorry about the late reply.

You overlooked "There should be one-- and preferably only one --
obvious way to do it.",  which in this case is join()

To me the current implementation is blatantly correct. sum is an
operation on a list of numeric values, returning a numeric value -
this is why we have the seemingly strange "".join() rather than [].join
("")

I think duck typing is wonderful so long as its specific applications
make sense. We don't handle integers being passed to len() do we?
Technically we could return the number of digits but it wouldn't make
sense as len() works on iterables.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is python so sad?

2009-10-27 Thread Donn
> > def ...(...(:
> > ...
> > class ...(...(:
> I disagree. It looks like one smiley is drooling into the other smiley's
>  mouth. Two smileys, one function? Yuk!
That *def*initely has no *class* ... :P

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


Re: how to modify row content of file in python?

2009-10-27 Thread Simon Hibbs
On 27 Oct, 07:55, holmes86  wrote:
> hi,everyone
>
> Is there function of modify row content in python? just like 'sed' in
> shell,thanks

You would do something like this, which acepts a CSV file from stdin
and sends the first column to stdout (prints it), which you could
redirect to a file or pipe to another command.

import sys

with infile = sys.stdin.readlines():
for line in infile.readlines():
columns = line.split(',')
print columns[0]


This code is not tested as Windows Explorer just crashed on my box
(effing windows - I'm at work so no Mac. *sob*).

One thing to look out for is that 'columns' is being created each time
through the loop, which works fine. If you modified the code to append
to it instead, you would need to create it before entering the loop as
you can't append to something that doesn't exist.


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


[ANN]: yappi v0.2 beta

2009-10-27 Thread Oktaka Com
Hi,

yappi(Yet Another Python Profiler) is a C extension that have
multithreading profiling capability. Profiler can be started from any
thread at any time. All threads in the attached interpreter will be
profiled.

Changes:
- 8 multithreading related issues/bugs are fixed.
- 1 memory leak(reference leak) bug fixed.
- add a get_stats() function to retrieve statictics as a list. Sorting
order and sorting column and result limit can be adjusted via this new
function.
- static pool and list can be adjusted at compile time.
- Robustness: Memory Allocation/OS/Python VM related error(s) should
be propagated to the application,
  profiler should be as transparent as possible.

Misc:
- Documentation and API is still on its way... See the usage in the
web page or read the yappi.py file in the release. Names are self
explanatory.
- Testing of the profiler on a game server for about one month is
completed.

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


Re: how to get os.system () call to cooperate on Windows

2009-10-27 Thread TerryP
On Oct 26, 10:00 am, Anthra Norell  wrote:
> The function "os.system
> ('copy file_name directory_name')" turns out doesn't do anything except
> flashing a DOS command window for half a second. So my question is: How
> can one copy files on the OS level?

Under a Windows system the built in command, copy, is a pile of crap
and xcopy is not much fun; you need to screw with it at the command
prompt to find the exact usage.

The formal way to copy files on the 'OS level' is by way of a system
call. I believe under Windows NT, this would be the CopyFile family;
using that through cctypes doesn't sound like fun.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: : yappi v0.2 beta

2009-10-27 Thread Oktaka Com
On Oct 27, 3:51 pm, Oktaka Com  wrote:
> Hi,
>
> yappi(Yet Another Python Profiler) is a C extension that have
> multithreading profiling capability. Profiler can be started from any
> thread at any time. All threads in the attached interpreter will be
> profiled.
>
> Changes:
> - 8 multithreading related issues/bugs are fixed.
> - 1 memory leak(reference leak) bug fixed.
> - add a get_stats() function to retrieve statictics as a list. Sorting
> order and sorting column and result limit can be adjusted via this new
> function.
> - static pool and list can be adjusted at compile time.
> - Robustness: Memory Allocation/OS/Python VM related error(s) should
> be propagated to the application,
>   profiler should be as transparent as possible.
>
> Misc:
> - Documentation and API is still on its way... See the usage in the
> web page or read the yappi.py file in the release. Names are self
> explanatory.
> - Testing of the profiler on a game server for about one month is
> completed.
>
> Sumer Cip

Forgot to give the project web page:) Here it is:


http://code.google.com/p/yappi/


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


anydbm, gdbm, dbm

2009-10-27 Thread Lacrima
Hello!

I want to store some data, using anydbm module.
According to docs the object returned by anydbm.open() supports most
of the same functionality as dictionaries; keys and their
corresponding values can be stored, retrieved, and deleted...

I don't understand how I can make a table in DBM database, or a row in
a table. Or all data must be stored just as key-value pairs?

Suppose my table consists of two columns: 'first name' and 'last
name'. How can I make such table and write there first and last names
for, say, two any persons?

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


Re: Web development with Python 3.1

2009-10-27 Thread Dotan Cohen
Why the push to use a framework, and why the resistance from the OP?

Does the OP need to work with cookies or other http-specific features?
In fact, other than cookies, what http-specific features exist? Does
Python have a built-in framework for making available GET and POST
variables?  Database queries should be no different than in other
Python apps.


-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web development with Python 3.1

2009-10-27 Thread Diez B. Roggisch
Dotan Cohen wrote:

> Why the push to use a framework, and why the resistance from the OP?
> 
> Does the OP need to work with cookies or other http-specific features?
> In fact, other than cookies, what http-specific features exist?

declarative mapping of urls to code, of code to templates, abstracting away
the details of GET and POST, validating and decoding parameters, especially
if these become larger repetitive structures like several addresses of a
user, re-rendering invalid form-data, working with HTML or JSON as output,
managing transactions, providing a error-reporting-infrastructure

The list continues.


> Does 
> Python have a built-in framework for making available GET and POST
> variables?  Database queries should be no different than in other
> Python apps.

Yes, in the end of the day, it's all python.

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


Re: anydbm, gdbm, dbm

2009-10-27 Thread Tim Chase

Lacrima wrote:

I want to store some data, using anydbm module.
According to docs the object returned by anydbm.open() supports most
of the same functionality as dictionaries; keys and their
corresponding values can be stored, retrieved, and deleted...

I don't understand how I can make a table in DBM database, or a row in
a table. Or all data must be stored just as key-value pairs?


Yes, all data for the dbm variants is purely string->string 
mapping pairs.  Similarly, dictionaries don't natively allow you 
to store columns in them...they are just key->value data-stores.



Suppose my table consists of two columns: 'first name' and 'last
name'. How can I make such table and write there first and last names
for, say, two any persons?



*dbm provides no columns unless you hack them such as

  db[key] = DELIMITER.join([lastname, firstname])

and then unhack them:

  lastname, firstname = db[key].split(DELIMITER, 1)

As a variant of this, you might be able to use pickle/shelve to 
stash your multi-content object as a string-value.


Alternatively, you could use something like

  db["%s_first" % key] = firstname
  db["%s_last" % key] = lastname

assuming your keys didn't confound you.

-tkc




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


Apologies.. please disregard, delete desktop dating

2009-10-27 Thread Robert LaMarca



Hi... 

thought i was simply accepting an invitation from a friend on a social network 
(yes, desktop dating.. no i did no think i was going to date the person.. just 
thought it was a regular social network thing with an annoying cute name and i 
was just going to be nice and accept) 

.. turns out to be a very bad site .. 
please delete any message from desktop dating.. 

they are evil

thanks for your understanding in this moment of infamy
-- 
http://mail.python.org/mailman/listinfo/python-list


Tryton 1.4 is available

2009-10-27 Thread ced
Tryton is a three-tiers high-level general purpose application
platform under the license GPL-3 written in Python and using
PostgreSQL as database engine.
It is the core base of a complete business solution providing
modularity, scalability and security.

This new series comes up with new modules, security and performance
improvements as well as the SQLite support and welcomes the arrival of
Neso, the standalone version of Tryton. As usual, database migration
is completely automated (and works on databases created with both the
1.0 and 1.2 series). Most of bugfixes from the last 6 months of
developments have already been backported in the 1.0 and 1.2 series.

The most noteworthy new features are:

- The add of SQLite support as DBMS
- The Neso standalone version of Tryton
- The cache improvement on the server thus ensuring that each record
is read at most once in the same transaction
- Wizards optionally preserve their sizes from successive calls
- The new filters "Starts with" and "Ends with" on fields containing
strings
- The reload of modules if files have changed
- CalDAV for calendar management and CardDAV for contact management
- LDAP authentication
- Project management
- The possibility to define sale price list per party.

A more complete list of the new features on: http://www.tryton.org/news.html

:Homepage:http://www.tryton.org/
:Downloads:   http://www.tryton.org/downloads.html
:Screenshots: http://www.tryton.org/screenshots.html
:Demo: http://www.tryton.org/demo.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: restriction on sum: intentional bug?

2009-10-27 Thread Luis Zarrabeitia
On Tuesday 27 October 2009 07:29:46 am Steve wrote:
> To me the current implementation is blatantly correct. sum is an
> operation on a list of numeric values, returning a numeric value -
> this is why we have the seemingly strange "".join() rather than [].join
> ("")

But then, why does sum() accept non-numeric input? How does sum decides if the 
arguments are "numbers", given that it accepts almost everything that defines 
__add__ (except strings)?

I really never tried to sum() strings before, but it makes sense that, if 
sum() already checks if the argument is a string before, it should do 
the "".join instead of returning an error.

Also, why is there a special case for the strings, but not for the tuples? 
Doesn't sum(((1,) for _ in xrange(100)),()) also have quadratic behaviour, 
creating and destroying intermediate tuples? And what happens with lists? 

-- 
Luis Zarrabeitia (aka Kyrie)
Fac. de Matemática y Computación, UH.
http://profesores.matcom.uh.cu/~kyrie
-- 
http://mail.python.org/mailman/listinfo/python-list


urllib.FTP.stor...() freeze mystery

2009-10-27 Thread Anthra Norell

Hi,
  I made a bunch of web pages and am now trying to upload them to a 
hosting service. I have an ftplib.FTP object that connects just fine. It 
calls storbinary () and storlines () (as appropriate) inside a loop 
iterating through my html and jpg files. Calling either of the stor... 
methods from the IDLE command line works beautifully. The loop, however, 
freezes after exactly seven successful passes. Ctrl-C doesn't stop the 
freeze. I have to open a new IDLE window and start over. A second 
attempt failed the exact same way. Could there be a limit on open files 
on the server side and the files I upload not closing for some reason? 
Knowing little more than nothing about communicating with a server I am 
totally fazed and will be most grateful for expert suggestions.


Frederic


--

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


Hide imports from a module

2009-10-27 Thread Jorge
Hi,
I'm making an executable fiel (win32) with py2exe.
The application is in python 2.6 and uses the firebird driver kinterbasdb.
It make the exe but when the application try to use the kinterbasdb module
gives
this error:
No Module named typeconv_24plus
in this post
http://groups.google.com/group/PyInstaller/tree/browse_frm/month/2007-05?_done=%2Fgroup%2FPyInstaller%2Fbrowse_frm%2Fmonth%2F2007-05%3F&pli=1
mahasamatman say to hide the  'typeconv_24plus' from the imports of
kinterbasdb.

My question is how can I do that?

Thanks in advance for your help.

Regards,

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


Re: unicode and dbf files

2009-10-27 Thread Ethan Furman

John Machin wrote:

On Oct 27, 7:15 am, Ethan Furman  wrote:

>

Let me rephrase -- say I get a dbf file with an LDID of \x0f that maps
to a cp437, and the file came from a german oem machine... could that
file have upper-ascii codes that will not map to anything reasonable on
my \x01 cp437 machine?  If so, is there anything I can do about it?


ASCII is defined over the first 128 codepoints; "upper-ascii codes" is
meaningless. As for the rest of your question, if the file's encoded
in cpXXX, it's encoded in cpXXX. If either the creator or the reader
or both are lying, then all bets are off.


My confusion is this -- is there a difference between any of the various 
cp437s?  Going down the list at ESRI: 0x01, 0x09, 0x0b, 0x0d, 0x0f, 
0x11, 0x15, 0x18, 0x19, and 0x1b all map to cp437, and they have names 
such as US, Dutch, Finnish, French, German, Italian, Swedish, Spanish, 
English (Britain & US)... are these all the same?




BTW, what are you planning to do with an LDID of 0x00?


Hmmm.  Well, logical choices seem to be either treating it as plain
ascii, and barfing when high-ascii shows up; defaulting to \x01; or
forcing the user to choose one on initial access.


It would be more useful to allow the user to specify an encoding than
an LDID.


I plan on using the same technique used in xlrd and xlwt, and allowing 
an encoding to be specified when the table is opened.  If not specified, 
it will use whatever the table has in the LDID field.




You need to be able to read files created not only by software like
VFP or dBase but also scripts using third-party libraries. It would be
useful to allow an encoding to override an LDID that is incorrect e.g.
the LDID implies cp1251 but the data is actually encoded in koi8[ru]

Read this: http://en.wikipedia.org/wiki/Code_page_437
With no LDID in the file and no encoding supplied, I'd be inclined to
make it barf if any codepoint not in range(32, 128) showed up.


Sounds reasonable -- especially when the encoding can be overridden.

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


What IDE has good git and python support?

2009-10-27 Thread Aweks
what do you use?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: restriction on sum: intentional bug?

2009-10-27 Thread Ethan Furman

Steve wrote:

On Oct 17, 8:28 pm, Tim Chase  wrote:


Christian Heimes wrote:


Alan G Isaac wrote:


On 10/16/2009 5:03 PM, Christian Heimes wrote:


It's not going to happen.


That's a prediction, not a justification.



It's not a prediction, it's a statement. It's not going to happend
because it violates Guido's gut feeling as well as the Zen of Python.


I'm not sure how it violates ZoP...particularly

Simple is better than complex.
  [complex is special casing or explaining why there's an error]
Special cases aren't special enough to break the rules.
  [raising an error is a special case]
Although practicality beats purity.
In the face of ambiguity, refuse the temptation to guess.
  [there's nothing ambiguous about sum() meaning "+"]
If the implementation is easy to explain, it may be a good idea.
  [sum(lst_of_strs) should do exactly what it says..."+" 'em]

-tkc



Sorry about the late reply.

You overlooked "There should be one-- and preferably only one --
obvious way to do it.",  which in this case is join()


That doesn't mean *only* one obvious way to do it, and more importantly 
it *does not* mean *only one way* to do it.




To me the current implementation is blatantly correct. sum is an
operation on a list of numeric values, returning a numeric value -
this is why we have the seemingly strange "".join() rather than [].join
("")

I think duck typing is wonderful so long as its specific applications
make sense. 


Duck typing is about not guessing what will make sense, or what needs 
will arise, to the users of our code.




We don't handle integers being passed to len() do we?
Technically we could return the number of digits but it wouldn't make
sense as len() works on iterables.


Ints do not have a __len__ method, so why should len() work on them? 
Strs, on the other hand, do have an __add__ method.


~Ethan~

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


Re: What IDE has good git and python support?

2009-10-27 Thread Mick Krippendorf
Aweks schrieb:
> what do you use?

Either of the following:
-> Vim + Eclim + Rope + pylint + PyDev + Eclipse + cygwin + WindowsXP
-> Vim + Linux

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


Re: ANN: WHIFF += Mako & treeview & url rewrites

2009-10-27 Thread Aaron Watters
On Oct 27, 8:16 am, Aaron Watters  wrote:
> On Oct 27, 8:02 am, alex23  wrote:
>
> > If you need a full traceback, let me know.
>
> Well, yes, the bottom of the traceback would be more useful :).
>
>    -- Aaron Watters

Alex sent me the traceback (thanks!) and after consulting
the logs and the pages I figured out that the version of
Firefox in question was not ignoring my javascript links like
it should.  Instead FF was interpreting them as HTTP links to
pages that didn't exist -- which is perfectly idiotic -- so
WHIFF was complaining that it couldn't find the page (which
is correct).

Anyway, you shouldn't see this buglet any more -- if you
don't have javascript you will get a nice polite message
saying that the page doesn't work unless javascript is
enabled.

http://aaron.oirt.rutgers.edu/myapp/GenBankTree/index

I hope you like it again.  Thanks for the help!
   -- Aaron Watters

===

nobody ever got fired for buying IBM^H^H^HMicrosoft.
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Python course, San Francisco, Nov 9-11

2009-10-27 Thread wesley chun
*FINAL REMINDER*

come join us for another hardcore Python training course in San
Francisco coming up in a few weeks! we have a few more slots
available. bring your co-workers to take advantage of our multiple
registration discount. we also feature a steeper discount for those
who are primary/secondary teachers, students, as well as to those who
have been more severely impacted by the economy. here is my original
announcement for more info:

http://mail.python.org/pipermail/python-list/2009-September/196228.html

hope to meet you soon!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
"Python Fundamentals", Prentice Hall, (c)2009
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Inheriting and modifying lots of methods

2009-10-27 Thread Felipe Ochoa
I need to create a subclass from a parent class that has lots of
methods, and need to decorate all of these. Is there pythonic way of
doing this other than:

def myDecorator (meth):
@wraps(meth)
def newMeth (*args, **kw):
print("Changing some arguments here.")
return meth(newargs, **kw)
return newMeth

class Parent:
def method1(self,args):
pass
def method2(self,args):
# and so on...
def methodn(self,args):
pass

class Mine(Parent):
for thing in dir(Parent):
if type(eval("Parent."+thing)) == type(Parent.method1):
eval(thing) = myDecorator(eval("Parent." + thing))

I'm not even sure that this works! Thanks a lot!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inheriting and modifying lots of methods

2009-10-27 Thread Diez B. Roggisch
Felipe Ochoa wrote:

> I need to create a subclass from a parent class that has lots of
> methods, and need to decorate all of these. Is there pythonic way of
> doing this other than:
> 
> def myDecorator (meth):
> @wraps(meth)
> def newMeth (*args, **kw):
> print("Changing some arguments here.")
> return meth(newargs, **kw)
> return newMeth
> 
> class Parent:
> def method1(self,args):
> pass
> def method2(self,args):
> # and so on...
> def methodn(self,args):
> pass
> 
> class Mine(Parent):
> for thing in dir(Parent):
> if type(eval("Parent."+thing)) == type(Parent.method1):
> eval(thing) = myDecorator(eval("Parent." + thing))
> 
> I'm not even sure that this works! Thanks a lot!

It's not working, you can't assign to something eval'ed.

There are various options here, including metaclasses, but I think the
simplest is to write a simple function:

def decorate_methods(subclass):
for name in dir(subclass):
thing = getattr(subclass, name)
if isinstance(thing, types.MethodType):
   setattr(subclass, name, myDecorator(thing)) # maybe
myDecorator(thing.im_func) is better here


Simply invoke that function with "Mine" - or use a metaclass to do that
implicitly.

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


Re: IDLE python shell freezes after running show() of matplotlib

2009-10-27 Thread Donny
I have this problem as well. I'm on Windows XP (32-bit x86 processor)
using Python 2.6.4 and matplotlib 0.99.1 (installed with
matplotlib-0.99.1.win32-py2.6.exe). The IDLE version is 2.6.4. The
difficulty occurs for me during the first example of the (official?)
Pyplot tutorial at , so it is possible that many new users of pyplot
experience this same difficulty:

import matplotlib.pyplot as plt
plt.plot([1,2,3])
plt.ylabel('some numbers')
plt.show()

I see the plot, and I can close the plot window by clicking on the X
at the upper-right corner of the plot window. However, as Forrest
mentioned, IDLE does not then spit out the next command prompt, nor
does IDLE respond to a Ctrl-C.

I have found that by turning on pyplot's 'interactive mode', the above
problem does not occur:

import matplotlib.pyplot as plt
plt.ion()
plt.plot([1,2,3]) # plot opens after this command is issued, and new
command prompt appears
plt.ylabel('some numbers') # if plot is not closed before issuing this
command, then the open plot window is updated
plt.close() # same effect as manually click-closing the plot window

On Oct 24, 5:03 pm, Forrest Sheng Bao  wrote:
> I am having a weird problem on IDLE. After I plot something using show
> () of matplotlib, the python shell prompt in IDLE just freezes that I
> cannot enter anything and there is no new ">>>" prompt show up. I
> tried ctrl - C and it didn't work. I have to restart IDLE to use it
> again.
>
> My system is Ubuntu Linux 9.04. I used apt-get to install IDLE.

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


Python + twisted = Raindrop (in part)

2009-10-27 Thread Terry Reedy

Rrom:
First look: inside Mozilla's Raindrop messaging platform

http://arstechnica.com/open-source/news/2009/10/first-look-inside-mozillas-raindrop-messaging-platform.ars

"The backend components that are responsible for retrieving and 
processing messages are coded in Python on top of the Twisted networking 
framework."


Ok, front end is html/Javascript, DB is erlang-based

tjr

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


Re: Web development with Python 3.1

2009-10-27 Thread Martin v. Löwis
> I am very much new to Python, and one of my first projects is a simple
> data-based website. I am starting with Python 3.1 (I can hear many of
> you shouting "don't - start with 2.6"), but as far as I can see, none of
> the popular python-to-web frameworks (Django, CherryPy, web.py, etc.)
> are Python3 compatible yet.

That's not entirely true, see

http://wiki.python.org/moin/PortingDjangoTo3k

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web development with Python 3.1

2009-10-27 Thread Dotan Cohen
> declarative mapping of urls to code

Apache does this, unless I am misunderstanding you.


> of code to templates

Those who code in HTML don't need this. In any case it's not hard to
call a function in a class that writes the HTML before the content,
then write the content, then call another function that writes the
HTML after the content. This is how my sites are run, though in PHP
instead of Python. No prepackaged templates.

> abstracting away
> the details of GET and POST

GET is easy, just parse the HTTP request. I don't know how much of a
problem POST would be.


> validating and decoding parameters, especially
> if these become larger repetitive structures like several addresses of a
> user

This falls under database, cookies, or HTTP request parsing. Or am I
misunderstanding something again?


> re-rendering invalid form-data

Just add it into the HTML.


> working with HTML or JSON as output,

Same as writing to stdout, just output the HTTP headers first.


> managing transactions, providing a error-reporting-infrastructure
>

This does not differ from regular (non-web) Python coding.


> The list continues.
>

I would really like to know what else. So far, I am not convinced that
a framework offers anything that is not already easily accomplished in
Python.

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What IDE has good git and python support?

2009-10-27 Thread Joshua Kugler
Aweks wrote:
> what do you use?

WingIDE has excellent Python support (it's a Python IDE, after all), and the
latest version has full support for git.

j

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


Re: What IDE has good git and python support?

2009-10-27 Thread Chris Colbert
it depends on what i'm doing.

quick and dirty test script: ipython

a larger problem with code I am likely to use later: spyder

a multi-module large project (like wrapping opencv): Wing

Chris

On Tue, Oct 27, 2009 at 5:04 PM, Mick Krippendorf  wrote:
> Aweks schrieb:
>> what do you use?
>
> Either of the following:
> -> Vim + Eclim + Rope + pylint + PyDev + Eclipse + cygwin + WindowsXP
> -> Vim + Linux
>
> Mick.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web development with Python 3.1

2009-10-27 Thread geremy condra
On Tue, Oct 27, 2009 at 2:36 PM, Dotan Cohen  wrote:
>> declarative mapping of urls to code
>
> Apache does this, unless I am misunderstanding you.
>
>
>> of code to templates
>
> Those who code in HTML don't need this. In any case it's not hard to
> call a function in a class that writes the HTML before the content,
> then write the content, then call another function that writes the
> HTML after the content. This is how my sites are run, though in PHP
> instead of Python. No prepackaged templates.
>
>> abstracting away
>> the details of GET and POST
>
> GET is easy, just parse the HTTP request. I don't know how much of a
> problem POST would be.
>
>
>> validating and decoding parameters, especially
>> if these become larger repetitive structures like several addresses of a
>> user
>
> This falls under database, cookies, or HTTP request parsing. Or am I
> misunderstanding something again?
>
>
>> re-rendering invalid form-data
>
> Just add it into the HTML.
>
>
>> working with HTML or JSON as output,
>
> Same as writing to stdout, just output the HTTP headers first.
>
>
>> managing transactions, providing a error-reporting-infrastructure
>>
>
> This does not differ from regular (non-web) Python coding.
>
>
>> The list continues.
>>
>
> I would really like to know what else. So far, I am not convinced that
> a framework offers anything that is not already easily accomplished in
> Python.

Using a framework helps to ensure that your code is easy to maintain.
DRY isn't about saving time now, its about saving time six months
from now.

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


Re: Web development with Python 3.1

2009-10-27 Thread Dotan Cohen
> Using a framework helps to ensure that your code is easy to maintain.

I see, that is a good point. With someone else (the framework
maintainers) worrying about maintaining function such as HTTP request
parsers, a lot of work won't have to be [re]done.


> DRY isn't about saving time now, its about saving time six months
> from now.
>

I suppose in this case it's DRTW (don't reinvent the wheel) but the
same principle applies.


-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What IDE has good git and python support?

2009-10-27 Thread TerryP
The best IDE for git and python is bash :-P.


I use a mixture of FreeBSD, rxvt-unicode, GNU screen, zsh, vim, git,
Python, and Exuberant Ctags.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RELEASED Python 2.6.4

2009-10-27 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Barry Warsaw wrote:
> On behalf of the Python community, I'm happy to announce the  
> availability of Python 2.6.4.  This is the latest production-ready  
> version in the Python 2.6 series.
> 
> We had a little trouble with the Python 2.6.3 release; a number of  
> unfortunate regressions were introduced.  I take responsibility for  
> rushing it out, but the good news is that Python 2.6.4 fixes the known  
> regressions in 2.6.3.  We've had a lengthy release candidate cycle  
> this time, and are confident that 2.6.4 is a solid release.  We highly  
> recommend you upgrade to Python 2.6.4.
> 
> Please see the NEWS file for all the gory details.
> 
>  http://www.python.org/download/releases/2.6.4/NEWS.txt
> 
> Source tarballs and the Windows installers can be downloaded from the  
> Python 2.6.4 page.  The Mac OS X disk image will be uploaded soon.
> 
> http://www.python.org/download/releases/2.6.4/
> 
> For more information on Python 2.6 in general, please see
> 
> http://docs.python.org/whatsnew/2.6.html
> 
> Please report bugs for any Python version in the Python tracker.
> 
> http://bugs.python.org

Congratulations, and thaks for working to correct the issues with the
earlier release so quickly.


Tres.
- --
===
Tres Seaver  +1 540-429-0999  [email protected]
Palladion Software   "Excellence by Design"http://palladion.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkrnRaEACgkQ+gerLs4ltQ5yHACgt9CqCyIE8HfkKCNjSEAU3MB1
A70AoL/yJB9lcI+RrBe3/BlqChCweXvr
=K/lR
-END PGP SIGNATURE-

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


Re: What IDE has good git and python support?

2009-10-27 Thread Ryan Lynch
On Tue, Oct 27, 2009 at 12:04, Mick Krippendorf  wrote:
> Aweks schrieb:
>> what do you use?
>
> Either of the following:
> -> Vim + Eclim + Rope + pylint + PyDev + Eclipse + cygwin + WindowsXP
> -> Vim + Linux

A word of praise/warning about Eclipse: The Python integration is
pretty good--I especially like the debugger. But the git support is
lacking--it's nowhere near the level of SVN or CVS integration, though
it is basically usable.

I'm using Egit 0.5.0 on F11, with Eclipse 3.5.

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


Re: Web development with Python 3.1

2009-10-27 Thread Aaron Watters
On Oct 27, 10:26 am, "Diez B. Roggisch"  wrote:
...
> Yes, in the end of the day, it's all python.

For me, in the end of the day, it's all java or PHP.
But I'm working on that.  For my purposes the "frameworks"
don't really help much.  That's why I built WHIFF :).

http://aaron.oirt.rutgers.edu/myapp/docs/W1100_2200.TreeView

  -- Aaron Watters

===
If all you got is lemons, make lemonade.
  -- anon.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What IDE has good git and python support?

2009-10-27 Thread geremy condra
On Tue, Oct 27, 2009 at 11:56 AM, Aweks  wrote:
> what do you use?
> --
> http://mail.python.org/mailman/listinfo/python-list
>

On console only: vim + screen
On X: (vim or gedit) + terminator

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


Re: Web development with Python 3.1

2009-10-27 Thread geremy condra
On Tue, Oct 27, 2009 at 3:11 PM, Dotan Cohen  wrote:
>> Using a framework helps to ensure that your code is easy to maintain.
>
> I see, that is a good point. With someone else (the framework
> maintainers) worrying about maintaining function such as HTTP request
> parsers, a lot of work won't have to be [re]done.
>
>
>> DRY isn't about saving time now, its about saving time six months
>> from now.
>>
>
> I suppose in this case it's DRTW (don't reinvent the wheel) but the
> same principle applies.

Well, yes- but it's also DRY, and while DRTW (like the acronym, btw)
helps to prevent your code from being unreadable to someone else,
DRY helps to ensure that when you have to change something you
don't have to worry about changing it in 37 and a half other places
at the same time. Especially given how notoriously difficult it is to
do automated testing for web development, that's essential.

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


Re: Pause a thread/ execfile()

2009-10-27 Thread Aahz
In article <352fe298-75b1-4bc3-aca0-ecd0165f5...@h40g2000prf.googlegroups.com>,
Babloo   wrote:
>
>i have a small python application with GUI (frontend) which has
>various functions. I have a "RUN" button which runs python scripts in
>the background . It basically calls execfile() function internally
>which runs in a thread ,  to run the python script .
>
>I want to implement a "PAUSE" feature which would pause the running
>python script . So do that i have to either pause the thread in which
>execfile() runs or pause execfile itself .

You might be able to get something useful out of Python's debugger hooks
(create some kind of callback).
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

"You could make Eskimos emigrate to the Sahara by vigorously arguing --
at hundreds of screens' length -- for the wonder, beauty, and utility of
snow."  --PNH to rb in r.a.sf.f
-- 
http://mail.python.org/mailman/listinfo/python-list


Deeper copy than deepcopy

2009-10-27 Thread Scott Pakin
copy.deepcopy apparently preserves multiple references to the same object:

$ python
Python 2.5.2 (r252:60911, Jan  4 2009, 17:40:26)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import copy
>>> d = [1,2,3]
>>> r = copy.deepcopy([d]*3)
>>> r
[[1, 2, 3], [1, 2, 3], [1, 2, 3]]
>>> r[1][2] = 999
>>> d
[1, 2, 3]
>>> r
[[1, 2, 999], [1, 2, 999], [1, 2, 999]]
>>>

I wanted to wind up with r being [[1, 2, 3], [1, 2, 999], [1, 2, 3]].
What's the right way to construct r as a list of *independent* d lists?

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


Re: Web development with Python 3.1

2009-10-27 Thread Dotan Cohen
> Well, yes- but it's also DRY, and while DRTW (like the acronym, btw)
> helps to prevent your code from being unreadable to someone else,
> DRY helps to ensure that when you have to change something you
> don't have to worry about changing it in 37 and a half other places
> at the same time. Especially given how notoriously difficult it is to
> do automated testing for web development, that's essential.
>

That's what classes are for, no? Reuse code. I fail to see how using a
framework would reduce the need to use classes, provided that the need
exists.


-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inheriting and modifying lots of methods

2009-10-27 Thread Steven D'Aprano
On Tue, 27 Oct 2009 10:43:42 -0700, Felipe Ochoa wrote:

> I need to create a subclass from a parent class that has lots of
> methods, and need to decorate all of these. Is there pythonic way of
> doing this other than:
> 
> def myDecorator (meth):
> @wraps(meth)
> def newMeth (*args, **kw):
> print("Changing some arguments here.") return meth(newargs,
> **kw)
> return newMeth
> 
> class Parent:
> def method1(self,args):
> pass
> def method2(self,args):
> # and so on...
> def methodn(self,args):
> pass
> 
> class Mine(Parent):
> for thing in dir(Parent):
> if type(eval("Parent."+thing)) == type(Parent.method1):
> eval(thing) = myDecorator(eval("Parent." + thing))
> 
> I'm not even sure that this works! Thanks a lot!


eval() won't work there. exec might, but any time you think you need eval/
exec, you probably don't :)

You can probably do some magic with metaclasses, but the simplest 
solution would be something like this:

class Mine(Parent):
pass


import types
for name in dir(Mine):
attr = getattr(Mine, name)
if type(attr) in (types.MethodType, types.UnboundMethodType):
setattr(Mine, name, myDecorator(attr))


The above (probably) won't touch classmethods and staticmethods. 



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


Re: restriction on sum: intentional bug?

2009-10-27 Thread Steven D'Aprano
On Tue, 27 Oct 2009 05:29:46 -0700, Steve wrote:

> To me the current implementation is blatantly correct. sum is an
> operation on a list of numeric values, returning a numeric value - this
> is why we have the seemingly strange "".join() rather than [].join ("")

That is absolutely wrong. sum() works on anything with an __add__ method, 
including lists, tuples, and even strings provided you defeat the hand-
holding the function does:


>>> sum(["a", "b"], '')
Traceback (most recent call last):
  File "", line 1, in 
TypeError: sum() can't sum strings [use ''.join(seq) instead]
>>>
>>> class Helper:
... def __add__(self, other):
... return other
...
>>> sum(["a", "b"], Helper())
'ab'



> I think duck typing is wonderful so long as its specific applications
> make sense. We don't handle integers being passed to len() do we?
> Technically we could return the number of digits but it wouldn't make
> sense as len() works on iterables.

The number of digits in what base?

len() works on anything with a __len__ method. Not all iterables have a 
known length. The most important examples are iterators and generators:


>>> len(iter('a'))
Traceback (most recent call last):
  File "", line 1, in 
TypeError: object of type 'iterator' has no len()


And there's no guarantee that an object with __len__ is iterable:


>>> class Weird:
... def __len__(self):
... return 42
...
>>> len(Weird())
42
>>> list(Weird())
Traceback (most recent call last):
  File "", line 1, in 
TypeError: iteration over non-sequence


Admittedly it is an abuse of len() to create an non-iterable object with 
__len__, but you can do it.


Personally, I think that sum() should, at most, just emit a warning if 
you pass a string as the second argument. Anything more than that is 
needlessly nanny-like. Python let's you shoot yourself in the foot if you 
like, I don't see that the consequences of summing strings is so harmful 
that it needs to be exceptional. But apparently Guido disagrees, and so 
the behaviour will stay.



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


Form Parsing resouces

2009-10-27 Thread Tim Johnson
Using python 2.5 on linux.
I am an experienced web programmer. 8 years with python.
I have done the following in other programming languages, but not so far
in python:

1)Parse a form into alternating strings and tags.
2)Convert tags into dictionary-like objects.
 Said process would allow me to then modify the objects and in the same
 sequence print out the string along with the objects to stdout.

 The goal is to 
1)Read a form - with no special markups, pseudo attributes
 or "template code" - from a file. Parse as above.
2)Read a record from a database. 
3)Insert the column values into corresponding dictionary objects and then
 reproduce the form as "filled" in.

If such a module existed, it would be wonderful, but if not, pointing me
to a starting point would be most welcome. The starting point would be a
python module that read a string containing html tags and seperates the
tages from the string.

Example="""
This is my form

Enter Name  

""" 
## result 
["This is my form",
{"tagtype":"form","action":"some.cgi","name":"form0"},
"Enter Name ",
{"tagtype":"input","type":"text","size":"40","name":"firstname"}
{"tagtype":"/form"}]

FYI: I have looked at ClientForm. It appears that ClientForm enables the
reading of a form as a request, modifying it and sending it directly
back to a process. I need something to provide a form directly to
stdout to enable a user to edit it.

TIA
-- 
Tim 
[email protected]
http://www.akwebsoft.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Deeper copy than deepcopy

2009-10-27 Thread Cameron Simpson
On 27Oct2009 14:01, Scott Pakin  wrote:
| copy.deepcopy apparently preserves multiple references to the same object:
| 
| $ python
| Python 2.5.2 (r252:60911, Jan  4 2009, 17:40:26)
| [GCC 4.3.2] on linux2
| Type "help", "copyright", "credits" or "license" for more information.
| >>> import copy
| >>> d = [1,2,3]
| >>> r = copy.deepcopy([d]*3)
| >>> r
| [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
| >>> r[1][2] = 999
| >>> d
| [1, 2, 3]
| >>> r
| [[1, 2, 999], [1, 2, 999], [1, 2, 999]]
| >>>
| 
| I wanted to wind up with r being [[1, 2, 3], [1, 2, 999], [1, 2, 3]].
| What's the right way to construct r as a list of *independent* d lists?

Well, you would need to write your own. But consider this:

  x = [1, 2]
  x.append(x)

Your deepercopy() function will explode.

Probably the best method is to pre-munge the list you pass to deepcopy:

  d = [1,2,3]
  d3 = [d]*3
  # pre-copy the multiple references
  d3deeper = [ list(d3i) for d3i in d3 ]
  r = copy.deepcopy(d3deeper)

You can see this requires special knowledge of the structure you're
copying though.
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

The mere existence of a problem is no proof of the existence of a solution.
- Yiddish Proverb
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web development with Python 3.1

2009-10-27 Thread geremy condra
On Tue, Oct 27, 2009 at 4:52 PM, Dotan Cohen  wrote:
>> Well, yes- but it's also DRY, and while DRTW (like the acronym, btw)
>> helps to prevent your code from being unreadable to someone else,
>> DRY helps to ensure that when you have to change something you
>> don't have to worry about changing it in 37 and a half other places
>> at the same time. Especially given how notoriously difficult it is to
>> do automated testing for web development, that's essential.
>>
>
> That's what classes are for, no? Reuse code. I fail to see how using a
> framework would reduce the need to use classes, provided that the need
> exists.

...frameworks use classes. They just don't make you write all of them.

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


Re: Web development with Python 3.1

2009-10-27 Thread Diez B. Roggisch

Dotan Cohen schrieb:

Well, yes- but it's also DRY, and while DRTW (like the acronym, btw)
helps to prevent your code from being unreadable to someone else,
DRY helps to ensure that when you have to change something you
don't have to worry about changing it in 37 and a half other places
at the same time. Especially given how notoriously difficult it is to
do automated testing for web development, that's essential.



That's what classes are for, no? Reuse code. I fail to see how using a
framework would reduce the need to use classes, provided that the need
exists.



A webframework is *written* in python. Your whole line of argumentation 
boils down to "I can write things myself in python, why use 
libraries/frameworks". Yes. You can also delete your standard-lib, and 
code everything in there yourself - with the same argument.


Using a framework is about proven solutions for common problems, letting 
you focus on working on your actual application code.


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


Re: Form Parsing resouces

2009-10-27 Thread geremy condra
On Tue, Oct 27, 2009 at 5:16 PM, Tim Johnson  wrote:
> Using python 2.5 on linux.
> I am an experienced web programmer. 8 years with python.
> I have done the following in other programming languages, but not so far
> in python:
>
> 1)Parse a form into alternating strings and tags.
> 2)Convert tags into dictionary-like objects.
>  Said process would allow me to then modify the objects and in the same
>  sequence print out the string along with the objects to stdout.
>



Taken a look at xml.dom.minidom? Should do everything you're asking.

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


Re: Deeper copy than deepcopy

2009-10-27 Thread Cameron Simpson
On 28Oct2009 08:23, I wrote:
| | I wanted to wind up with r being [[1, 2, 3], [1, 2, 999], [1, 2, 3]].
| | What's the right way to construct r as a list of *independent* d lists?
| 
| Well, you would need to write your own. But consider this:
|   x = [1, 2]
|   x.append(x)
| Your deepercopy() function will explode.

I've thought of a comprimise that would work automatically: deepcopy
tracks all the objects in the structure and replicates their multiple
uses. For your purposes, you could write a version of deepcopy that did
a depth-first recursion and only tracked the ancestor objects.

That way the above x.append(x) recursive list would not duplicate the
inner "x", but an "x" in two subbranches of a structure _would_ be
replicated i.e. this:

  x = [1,2]
  y = [x, x]

would get two independent "x"s.

However, it would still mean a recursive structure would get non-independent
"x"s. Which is necessary to avoid an infinite copy but breaks your
requirement.
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

Every technical corrigendum is met by an equally troublesome new defect report.
- Norman Diamond 
-- 
http://mail.python.org/mailman/listinfo/python-list


Embedded python on systems without python installed

2009-10-27 Thread KillSwitch
I have python successfully embedded in a program I wrote.

What files do I need and where do I need to put them so that it can
run on systems that don't have python installed?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Deeper copy than deepcopy

2009-10-27 Thread Gary Herron

Scott Pakin wrote:

copy.deepcopy apparently preserves multiple references to the same object:

$ python
Python 2.5.2 (r252:60911, Jan  4 2009, 17:40:26)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import copy
>>> d = [1,2,3]
>>> r = copy.deepcopy([d]*3)
>>> r
[[1, 2, 3], [1, 2, 3], [1, 2, 3]]
>>> r[1][2] = 999
>>> d
[1, 2, 3]
>>> r
[[1, 2, 999], [1, 2, 999], [1, 2, 999]]
>>>

I wanted to wind up with r being [[1, 2, 3], [1, 2, 999], [1, 2, 3]].
What's the right way to construct r as a list of *independent* d lists?

Thanks,
-- Scott
  


Try this:

>>>
>>> d = [1,2,3]
>>> r = [[x for x in d] for i in range(3)]
>>> r[1][2] = 999
>>> r
[[1, 2, 3], [1, 2, 999], [1, 2, 3]]

Gary Herron

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


Re: Embedded python on systems without python installed

2009-10-27 Thread Stef Mientki

KillSwitch wrote:

I have python successfully embedded in a program I wrote.

What files do I need and where do I need to put them so that it can
run on systems that don't have python installed?
  

I embed python in Delphi apps, and the only thing I add is python24.dll,
which I put in the same directory as the Delphi executable,
(but i you want a less clean install, you can put the dll also in the 
windows directory)


cheers,
Stef
--
http://mail.python.org/mailman/listinfo/python-list


Re: Embedded python on systems without python installed

2009-10-27 Thread Stef Mientki

KillSwitch wrote:

I have python successfully embedded in a program I wrote.

What files do I need and where do I need to put them so that it can
run on systems that don't have python installed?
  

I embed python in Delphi apps, and the only thing I add is python24.dll,
which I put in the same directory as the Delphi executable,
(but if you want a less clean install, you can put the dll also in the 
windows directory)


cheers,
Stef
--
http://mail.python.org/mailman/listinfo/python-list


Re: transpose array

2009-10-27 Thread Peter Otten
yoshco wrote:

> hello everyone
> i have 3 arrays
> xVec=[a1,a2,a3,a4,a5]
> yVec=[b1.b2.b3.b4.b5]
> zVec=[c1,c2,c3,c4,c5]
> 
> and i want to output them to a ascii file like so
> 
> a1,b1,c1
> a2,b2,c2
> a3,b3,c3
> ...
> 
> now i'm using
> 
>print >>f, str(xVec).replace('[',' ').replace(']', ' ')
>print >>f, str(yVec).replace('[',' ').replace(']', ' ')
>print >>f, str(zVec).replace('[',' ').replace(']', ' ')
> 
> which dumps them like
> 
>  a1,a2,a3,a4,a5
>  b1.b2.b3.b4.b5
>  c1,c2,c3,c4,c5

>>> xVec=[a1,a2,a3,a4,a5]
>>> yVec=[b1,b2,b3,b4,b5]
>>> zVec=[c1,c2,c3,c4,c5]
>>> import sys, csv
>>> from itertools import izip
>>> csv.writer(sys.stdout).writerows(izip(xVec, yVec, zVec))
a1,b1,c1
a2,b2,c2
a3,b3,c3
a4,b4,c4
a5,b5,c5

Peter

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


Re: transpose array

2009-10-27 Thread Edward A. Falk
In article ,
yoshco   wrote:
>hello everyone
>i have 3 arrays
>xVec=[a1,a2,a3,a4,a5]
>yVec=[b1.b2.b3.b4.b5]
>zVec=[c1,c2,c3,c4,c5]
>
>and i want to output them to a ascii file like so
>
>a1,b1,c1
>a2,b2,c2
>a3,b3,c3
>...

Elegant or obfuscated, you be the judge:

  vv = [xVec, yVec, zVec]

  for i in range(len(xVec)):
print >>f,  ", ".join([x[i] for x in vv])


To be honest, I'd be more likely to do it like this, for readability if
for no other reason:

  for i in range(len(xVec)):
print >>f, "%f, %f, %f" % (xVec[i], yVec[i], zVec[i])



It might help if we knew what you're *really* trying to do.

-- 
-Ed Falk, [email protected]
http://thespamdiaries.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: transpose array

2009-10-27 Thread Ishwor Gurung
Hi,

>> xVec=[a1,a2,a3,a4,a5]
>> yVec=[b1.b2.b3.b4.b5]
>> zVec=[c1,c2,c3,c4,c5]
>>
>> and i want to output them to a ascii file like so
>>
>> a1,b1,c1
>> a2,b2,c2
>> a3,b3,c3
>> ...
>>
>> now i'm using
>>
>>    print >>f, str(xVec).replace('[',' ').replace(']', ' ')
>>    print >>f, str(yVec).replace('[',' ').replace(']', ' ')
>>    print >>f, str(zVec).replace('[',' ').replace(']', ' ')
>>
>> which dumps them like
>>
>>  a1,a2,a3,a4,a5
>>  b1.b2.b3.b4.b5
>>  c1,c2,c3,c4,c5
>
 xVec=[a1,a2,a3,a4,a5]
 yVec=[b1,b2,b3,b4,b5]
 zVec=[c1,c2,c3,c4,c5]
 import sys, csv
 from itertools import izip
 csv.writer(sys.stdout).writerows(izip(xVec, yVec, zVec))
> a1,b1,c1
> a2,b2,c2
> a3,b3,c3
> a4,b4,c4
> a5,b5,c5

Or, http://docs.scipy.org/doc/numpy/reference/generated/numpy.transpose.html :-)
-- 
Regards,
Ishwor Gurung
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: transpose array

2009-10-27 Thread Rhodri James
On Tue, 27 Oct 2009 23:09:11 -, Edward A. Falk   
wrote:


In article  
,

yoshco   wrote:

hello everyone
i have 3 arrays
xVec=[a1,a2,a3,a4,a5]
yVec=[b1.b2.b3.b4.b5]
zVec=[c1,c2,c3,c4,c5]

and i want to output them to a ascii file like so

a1,b1,c1
a2,b2,c2
a3,b3,c3
...


Elegant or obfuscated, you be the judge:

  vv = [xVec, yVec, zVec]

  for i in range(len(xVec)):
print >>f,  ", ".join([x[i] for x in vv])


Surely more Pythonic would be:

for t in zip(xVec, yVec, zVec):
print >>f, ", ".join(t)

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Tkinter scrolling

2009-10-27 Thread Felipe Ochoa
So I've been trying to put Frederik Lundh's ScrolledFrame (
http://effbot.org/zone/tkinter-autoscrollbar.htm ) into a class, and
have the frame do more useful things. I tried switching out the
references to root to a frame, and moving it into a class. It runs,
until you try to make the frame/canvas/root smaller than its contents.
>From an interactive session, saying something like:

>>> f.botframe["width"] = 200
>>> f.topframe["width"] = 200
>>> f.canvas["width"] = 200

will make the window blink three times, and return to its original
size. Here's the code:

import tkinter as tk

class AutoScrollbar(tk.Scrollbar):
# a scrollbar that hides itself if it's not needed.  only
# works if you use the grid geometry manager.
def set(self, lo, hi):
if float(lo) <= 0.0 and float(hi) >= 1.0:
# grid_remove is currently missing from Tkinter!
self.tk.call("grid", "remove", self)
else:
self.grid()
tk.Scrollbar.set(self, lo, hi)
def pack(self, **kw):
raise tk.TclError("cannot use pack with this widget")
def place(self, **kw):
raise tk.TclError( "cannot use place with this widget")

class ScrollFrame:
def __init__(self,master):
self.topframe = tk.Frame(master)
vscrollbar = AutoScrollbar(self.topframe)
vscrollbar.grid(row=0, column=1, sticky='ns')
hscrollbar = AutoScrollbar(self.topframe,
orient=tk.HORIZONTAL)
hscrollbar.grid(row=1, column=0, sticky='ew')

self.canvas = tk.Canvas(self.topframe,
yscrollcommand=vscrollbar.set,
xscrollcommand=hscrollbar.set)
self.canvas.grid(row=0, column=0, sticky='news')

vscrollbar.config(command=self.canvas.yview)
hscrollbar.config(command=self.canvas.xview)

# make the canvas expandable
self.topframe.grid_rowconfigure(0, weight=1)
self.topframe.grid_columnconfigure(0, weight=1)

#
# create canvas contents

self.botframe = tk.Frame(self.canvas)
self.canvas.create_window(0, 0, anchor='nw',
window=self.botframe)

self.botframe.update_idletasks()

self.canvas.config(scrollregion=self.canvas.bbox("all"))

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


Re: How would you design scalable solution?

2009-10-27 Thread Jonathan Gardner
On Oct 27, 10:10 am, Bryan  wrote:
>
> How else to keep a record of every transaction, but not have the speed
> of the
> question "How many Things in Bucket x" depend on looking @ every
> transaction
> record ever made?

You can have three different tables in your database:

(1) The transaction log. (You described it above.)

(2) What the current state of the entire system is---where everything
is.

(3) A materialized view of the total of what is in each bucket.

Note that you didn't specify that the system should answer the
question "What is the history of this item?" or "What is the
historical contents of this bucket?" Because of this, you really don't
need (1). Gnucash has this requirement since people would like to go
back in time and see what happened historically.

Your requirements also don't specify that the system should answer the
question, "What is in this bucket right now?" Because of that, you
really don't need to expose the data in (2). However, I assume you'll
need some way of saying, "Can't move X from A to B because X isn't in
A!" so (2) is necessary.

(3) gives you exactly what you need, with linear look up by bucket ID
if you use a hash index for any number of buckets. You can also obtain
the value of all buckets linearly.

Do some research into what a "materialized view" is and how to keep it
in sync with the actual state of the data so that you can do this
properly. I believe that should solve your problem.

If you intend to implement this in memory by yourself, please
familiarize yourself on the various issues you will run into with
transactional and persistent data, especially with multi-threading if
you will allow it.

If you use a proper database to manage transactions for you, there is
no reason that the transaction log, current contents, and current
summary materialized view should ever get out of sync with each other,
as long as your transactions are all correct. For best results, write
a database function that does what you need and have all the clients
update the tables through it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Deeper copy than deepcopy

2009-10-27 Thread Steven D'Aprano
On Tue, 27 Oct 2009 15:16:15 -0700, Gary Herron wrote:

> Try this:
> 
> 
>  >>> d = [1,2,3]
>  >>> r = [[x for x in d] for i in range(3)]
>  >>> r[1][2] = 999
>  >>> r
> [[1, 2, 3], [1, 2, 999], [1, 2, 3]]


[x for x in d] is better written as d[:]


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


Re: transpose array

2009-10-27 Thread Steven D'Aprano
On Tue, 27 Oct 2009 15:26:55 -0700, yoshco wrote:

> hello everyone
> i have 3 arrays
> xVec=[a1,a2,a3,a4,a5]
> yVec=[b1.b2.b3.b4.b5]
> zVec=[c1,c2,c3,c4,c5]
>
> and i want to output them to a ascii file like so
> 
> a1,b1,c1
> a2,b2,c2
> a3,b3,c3
> ...


f = open('myfile.txt', 'w')
for t in zip(xVec, yVec, zVec):
f.write('%s, %s, %s\n' % t)
f.close()


If the lists are really huge, you should use itertools.izip() instead of 
zip().



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


Re: Embedded python on systems without python installed

2009-10-27 Thread Gabriel Genellina
En Tue, 27 Oct 2009 19:31:45 -0300, Stef Mientki   
escribió:

KillSwitch wrote:



I have python successfully embedded in a program I wrote.
What files do I need and where do I need to put them so that it can
run on systems that don't have python installed?


I embed python in Delphi apps, and the only thing I add is python24.dll,
which I put in the same directory as the Delphi executable,
(but i you want a less clean install, you can put the dll also in the  
windows directory)


In addition to that DLL, include as much of the standard library as you  
want in a 'Lib' subdirectory (at least os.py; it is used by the  
initialization code to determine the standard library location). Or  
nothing.


--
Gabriel Genellina

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


Re: ftpilb.FTP.stor...() freeze mystery

2009-10-27 Thread Gabriel Genellina

En Tue, 27 Oct 2009 07:53:36 -0300, Anthra Norell
 escribió:

  I am trying to upload a bunch of web pages to a hosting service. I  
have a connected ftplib.FTP object and can upload files manually from an  
IDLE command line using the methods storlines () for html files and  
storbinary () for the pictures. So far no problem. In order to upload  
the whole set of files I wrote a loop that iterates through the file  
names and calls either of the stor... () methods as appropriate. The  
loop successfully uploads eight of some twenty files and then freezes.  
Ctrl-C doesn't unlock the freeze. I have to kill the IDLE window which  
raises a confirmation request "are you sure? The program is still  
running." Having no alternative I am sure. I open a new IDLE window and  
start over. Every retry fails the exact same way.


  From the description alone I can't infer any problem. Certainly uploading
files with ftplib worked fine last time I tried. Try to remove all
unnecesary lines from your script, making it as small as possible but
still showing your problem, and post it here.

--
Gabriel Genellina

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


Re: ftpilb.FTP.stor...() freeze mystery

2009-10-27 Thread Gabriel Genellina

En Tue, 27 Oct 2009 07:53:36 -0300, Anthra Norell
 escribió:

  I am trying to upload a bunch of web pages to a hosting service. I  
have a connected ftplib.FTP object and can upload files manually from an  
IDLE command line using the methods storlines () for html files and  
storbinary () for the pictures. So far no problem. In order to upload  
the whole set of files I wrote a loop that iterates through the file  
names and calls either of the stor... () methods as appropriate. The  
loop successfully uploads eight of some twenty files and then freezes.  
Ctrl-C doesn't unlock the freeze. I have to kill the IDLE window which  
raises a confirmation request "are you sure? The program is still  
running." Having no alternative I am sure. I open a new IDLE window and  
start over. Every retry fails the exact same way.


From the description alone I can't infer any problem. Certainly
uploading
files with ftplib worked fine last time I tried. Try to remove all
unnecesary lines from your script, making it as small as possible but
still showing your problem, and post it here.

--
Gabriel Genellina

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


Re: how to get os.system () call to cooperate on Windows

2009-10-27 Thread Gabriel Genellina

En Tue, 27 Oct 2009 10:55:09 -0300, TerryP 
escribió:


On Oct 26, 10:00 am, Anthra Norell  wrote:

The function "os.system
('copy file_name directory_name')" turns out doesn't do anything except
flashing a DOS command window for half a second. So my question is: How
can one copy files on the OS level?


Under a Windows system the built in command, copy, is a pile of crap
and xcopy is not much fun; you need to screw with it at the command
prompt to find the exact usage.


Uh... well, not because you don't know the command syntax it becomes a
pile of crap...


The formal way to copy files on the 'OS level' is by way of a system
call. I believe under Windows NT, this would be the CopyFile family;
using that through cctypes doesn't sound like fun.


It's as simple as this:

  from ctypes import windll
CopyFile = windll.kernel32.CopyFileA
CopyFile("d:\\temp\\old.txt", "d:\\temp\\new.txt", True)

--
Gabriel Genellina

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


Re: Problem embedding Python.

2009-10-27 Thread Gabriel Genellina

En Tue, 27 Oct 2009 06:36:18 -0300, Brandon Keown
 escribió:

On Oct 27, 2:47 am, "Gabriel Genellina" 
wrote:


You didn't test for the fopen result; are you sure "test.py" exists in  
the current directory at the time you run it?


Ok, so I assumed that the file, if supplied without a path, would use
current working directory, which was evidently a false assumption.


Now that you've solved your problem, revise your conclusion. A file
without a path *is* searched in the current working directory - but that
directory may not be the one you think it is.

--
Gabriel Genellina

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


Re: Form Parsing resouces

2009-10-27 Thread Gabriel Genellina

En Tue, 27 Oct 2009 18:16:07 -0300, Tim Johnson 
escribió:


Example="""
This is my form

Enter Name  

"""
## result
["This is my form",
{"tagtype":"form","action":"some.cgi","name":"form0"},
"Enter Name ",
{"tagtype":"input","type":"text","size":"40","name":"firstname"}
{"tagtype":"/form"}]

FYI: I have looked at ClientForm. It appears that ClientForm enables the
reading of a form as a request, modifying it and sending it directly
back to a process. I need something to provide a form directly to
stdout to enable a user to edit it.


Try FormEncode http://formencode.org/

--
Gabriel Genellina

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


Re: how to get os.system () call to cooperate on Windows

2009-10-27 Thread Steven D'Aprano
On Tue, 27 Oct 2009 21:48:36 -0300, Gabriel Genellina wrote:

> En Tue, 27 Oct 2009 10:55:09 -0300, TerryP 
> escribió:
> 
>> On Oct 26, 10:00 am, Anthra Norell  wrote:
>>> The function "os.system
>>> ('copy file_name directory_name')" turns out doesn't do anything
>>> except flashing a DOS command window for half a second. So my question
>>> is: How can one copy files on the OS level?

[...]

> It's as simple as this:
> 
>from ctypes import windll
> CopyFile = windll.kernel32.CopyFileA
> CopyFile("d:\\temp\\old.txt", "d:\\temp\\new.txt", True)



Have I missed something? What's wrong with shutil? 

shutil.copyfile(source, destination) seems to work for me, even on 
Windows.


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


  1   2   >