ANN: SciPy 2009 early registration ends today

2009-07-23 Thread Jarrod Millman
Today is the last day to register for SciPy 2009 at the early bird rates.
Please register (http://conference.scipy.org/to_register )
by the end of the day to take advantage of the reduced early registration
rate.

The conference schedule is available here:
 http://conference.scipy.org/schedule

The special group rate for the Marriot Hotel is no longer available.  However,
there are a number of closer and less expensive choices still available:
 http://admissions.caltech.edu/visiting/accommodations
I've been staying at the Vagabond Inn for the last several years:
 http://www.vagabondinn-pasadena-hotel.com/
It is within easy walking distance of the conference and has just been
completely renovated.  Rooms at the Vagabond start at $79/night.

About the conference


SciPy 2009, the 8th Python in Science conference, will be held from
August 18-23, 2009 at Caltech in Pasadena, CA, USA.  The conference
starts with two days of tutorials to the scientific Python tools.
There will be two tracks, one for introduction of the basic tools to
beginners, and one for more advanced tools.  The tutorials will be
followed by two days of talks.  Both days of talks will begin with a
keynote address.  The first day’s keynote will be given by Peter
Norvig, the Director of Research at Google; while, the second keynote
will be delivered by Jon Guyer, a Materials Scientist in the
Thermodynamics and Kinetics Group at NIST.  The program committee will
select the remaining talks from submissions to our call for papers.
All selected talks will be included in our conference proceedings
edited by the program committee.  After the talks each day we will
provide several rooms for impromptu birds of a feather discussions.
Finally, the last two days of the conference will be used for a number
of coding sprints on the major software projects in our community.

For the 8th consecutive year, the conference will bring together the
developers and users of the open source software stack for scientific
computing with Python.  Attendees have the opportunity to review the
available tools and how they apply to specific problems.  By providing
a forum for developers to share their Python expertise with the wider
commercial, academic, and research communities, this conference
fosters collaboration and facilitates the sharing of software
components, techniques, and a vision for high level language use in
scientific computing.

For further information, please visit the conference homepage:
http://conference.scipy.org.

Important Dates
---

* Friday, July 3: Abstracts Due
* Wednesday, July 15: Announce accepted talks, post schedule
* Wednesday, July 22: Early Registration ends
* Tuesday-Wednesday, August 18-19: Tutorials
* Thursday-Friday, August 20-21: Conference
* Saturday-Sunday, August 22-23: Sprints
* Friday, September 4: Papers for proceedings due

Executive Committee
---

* Jarrod Millman, UC Berkeley, USA (Conference Chair)
* Gaël Varoquaux, INRIA Saclay, France (Program Co-Chair)
* Stéfan van der Walt, University of Stellenbosch, South Africa
(Program Co-Chair)
* Fernando Pérez, UC Berkeley, USA (Tutorial Chair)
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


ANN: easygconf 0.01

2009-07-23 Thread Florian Diesch

I'm happy to announce easygconf 0.01


Get it at http://www.florian-diesch.de/software/easygconf/

easygconf provids an easy, pythonic way to access GConf
http://projects.gnome.org/gconf/ through a dict-like interface.



Example
---

 from easygconf import GConfDict
 gc=GConfDict('/apps/test-application')

 gc['title']
 gc['title']='Hello world!'
 gc['title']
'Hello world!'

 gc['list']=range(3)
 gc['list']
(0, 1, 2)

 gc.unset('title')
 gc.unset('list')
 gc['title']
 gc['list']

 gc.sync()




   Florian
-- 
http://www.florian-diesch.de/
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


[ANN] EuroSciPy 2009 - first slides

2009-07-23 Thread Mike Müller

EuroSciPy 2009 - First Slides Available
===

The first slides for the talks at EuroSciPy are available:
http://www.euroscipy.org/presentations/slides/index.html

The abstracts of all talks can be found here:
http://www.euroscipy.org/presentations/abstracts/index.html


EuroSciPy 2009
==

We're pleased to announce the EuroSciPy 2009 Conference to be held in
Leipzig, Germany on July 25-26, 2009.

http://www.euroscipy.org

This is the second conference after the successful conference last
year. Again, EuroSciPy will be a venue for the European community of
users of the Python programming language in science.


Presentation Schedule
-
The schedule of presentations for the EuroSciPy conference is online:

http://www.euroscipy.org/presentations/schedule.html

We have 16 talks from a variety of scientific fields.
All about using Python for scientific work.

Registration


The registration fee is 150.00 € and will increase to 200.00 € for
on-site registration and registration after July 23, 2009.
Registration will include snacks and lunch for Saturday and Sunday.

Please register here:
http://www.euroscipy.org/registration.html


Important Dates
---

March 21Registration opens
May 8   Abstract submission deadline
May 15  Acceptance of presentations
May 30  Announcement of conference program
June 15 Early bird registration deadline
July 15 Slides submission deadline
July 20 - 24Pre-Conference courses
July 25/26  Conference
August 15   Paper submission deadline

Venue
-

mediencampus
Poetenweg 28
04155 Leipzig
Germany

See http://www.euroscipy.org/venue.html for details.


Help Welcome


You would like to help make the EuroSciPy 2009 a success?
Here are some ways you can get involved:
* attend the conference
* submit an abstract for a presentation
* give a lightning talk
* make EuroSciPy known:
- distribute the press release (http://www.euroscipy.org/media.html)
  to scientific magazines or other relevant media
- write about it on your website
- in your blog
- talk to friends about it
- post to local e-mail lists
- post to related forums
- spread flyers and posters in your institution
- make entries in relevant event calendars
- anything you can think of
* inform potential sponsors about the event
* become a sponsor

If you're interested in volunteering to help organize things
or have some other idea that can help the conference, please
email us at mmueller at python-academy dot de.


Sponsorship
---

Do you like to sponsor the conference?
There are several options available:

http://www.euroscipy.org/sponsors/become_a_sponsor.html


Pre-Conference Courses
--

Would you like to learn Python or about some of the most used scientific
libraries in Python? Then the Python Summer Course [1] might be for
you. There are two parts to this course:

* a two-day course Introduction to Python [2] for people with
  programming experience in other languages and
* a three-day course Python for Scientists and Engineers [3] that
  introduces some of the most used Python tools for scientists and
  engineers such as NumPy, PyTables, and matplotlib

Both courses can be booked individually [4]. Of course, you can attend
the courses without registering for EuroSciPy.

[1] http://www.python-academy.com/courses/python_summer_course.html
[2] http://www.python-academy.com/courses/python_course_programmers.html
[3] http://www.python-academy.com/courses/python_course_scientists.html
[4] http://www.python-academy.com/courses/dates.html

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

   Support the Python Software Foundation:
   http://www.python.org/psf/donations/


Re: comments? storing a function in an object

2009-07-23 Thread Aahz
In article f3d88edf-b5d3-43e4-89a3-b05ef0f55...@p28g2000vbn.googlegroups.com,
Carl Banks  pavlovevide...@gmail.com wrote:

You have to be REALLY REALLY careful not to pass any user-supplied
data to it if this is a server running on your computer, of course.

Unless, of course, your users are paying for this service.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

The volume of a pizza of thickness 'a' and radius 'z' is
given by pi*z*z*a
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: JavaScript toolkits (was Re: ANN: Porcupine Web Application Server 0.6 is released!)

2009-07-23 Thread Aahz
In article mailman.3451.1248139114.8015.python-l...@python.org,
D'Arcy J.M. Cain da...@druid.net wrote:
On 20 Jul 2009 17:10:55 -0700
a...@pythoncraft.com (Aahz) wrote:
I understand what you want but I can't see how a toolkit can do that.
How do you program graceful?  It seems pretty application specific.
 
 Presumably the JS toolkit generates both code and HTML.  Actions that
 normally get executed by JS should degrade to plain HTML links and form
 submits (or possibly not display at all if it's a pure convenience).

As I said, I do understand what you are after but I still think it is a
judgement call.  What defines convenience?  How does the library know
what is essential and what is pretty?

Presumably a JS toolkit designed for this purpose would have an API to
specify the handling of such issues.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

The volume of a pizza of thickness 'a' and radius 'z' is
given by pi*z*z*a
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: JavaScript toolkits (was Re: ANN: Porcupine Web Application Server 0.6 is released!)

2009-07-23 Thread Aahz
In article 1c994086-8c58-488f-b3b3-6161c4b2b...@k30g2000yqf.googlegroups.com,
Paul Boddie  p...@boddie.org.uk wrote:
On 20 Jul, 18:00, a...@pythoncraft.com (Aahz) wrote:

 Out of curiosity, are there any JavaScript toolkits that generate code
 that degrades gracefully when JavaScript is disabled?

You mean Web toolkits which use JavaScript, I presume. I have
written (and use myself) a toolkit/framework called XSLForms (part of
the XSLTools distribution) which supports in-page updates (AJAX,
effectively) that degrade to vanilla whole-page requests if JavaScript
is switched off:

http://www.boddie.org.uk/python/XSLTools.html

Thanks!  I'll take a look after OSCON.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

The volume of a pizza of thickness 'a' and radius 'z' is
given by pi*z*z*a
-- 
http://mail.python.org/mailman/listinfo/python-list


MySQLdb for Python 3.1 getting close?

2009-07-23 Thread John Nagle

  Is MySQLdb available for Python 3.1 yet?

  http://sourceforge.net/projects/mysql-python/

says the last supported Python version is 2.5.  Any progress in sight?

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


Re: Help understanding the decisions *behind* python?

2009-07-23 Thread Gabriel Genellina

En Wed, 22 Jul 2009 11:36:51 -0300, Inky 788 inky...@gmail.com escribió:

On Jul 22, 2:36 am, Hendrik van Rooyen hend...@microcorp.co.za
wrote:



The good reason is the immutability, which lets you use
a tuple as a dict key.  


Thanks for the reply Hendrik (and Steven (other reply)). Perhaps I'm
just not sophisticated enough, but I've never wanted to use a list/
tuple as a dict key. This sounds like obscure usage, and a bit
contrived as a reason for having *both* lists and tuples.


Many people posted useful examples of tuples as dictionary keys in this
thread. Just to add another one (emulate SQL GROUP BY):

ope_by_dept = defaultdict(int)
total_times = defaultdict(float)

for dept_name, ope_name, ope_date, engineer in list_of_operations:
ope_by_dept[dept_name, ope_start.month] += 1
total_times[dept_name, engineer] += ope_end - ope_start

print Operations per department per month
for dept_name, month in sorted(ope_by_dept):
 print dept_name, month, ope_by_dept[dept_name, month]

--
Gabriel Genellina

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


Re: logging outgoing HTTP POST message and incoming response message

2009-07-23 Thread Gabriel Genellina

En Wed, 22 Jul 2009 18:18:37 -0300, scriptlear...@gmail.com
scriptlear...@gmail.com escribió:

On Jul 22, 1:54 pm, Diez B. Roggisch de...@nospam.web.de wrote:

You can use proxy-tools such as tcpmon or sniff traffic using wireshark.


Thanks,
but I am trying to enable some debug mode to log all outgoing and
incoming messages for certain period of time, and running another
proxy-tool is not very ideal.  It would be great to log it in some log
file.


You may install a custom HTTPHandler:

class LoggingHTTPConnection(httplib.HTTPConnection):

 def request(self, method, url, body=None, headers={}):
 print method, url, headers
 httplib.HTTPConnection.request(self, method, url, body, headers)

 def getresponse(self):
 response = httplib.HTTPConnection.getresponse(self)
 print response.status, response.msg
 return response

class LoggingHTTPHandler(urllib2.HTTPHandler):
 def http_open(self, req):
 return self.do_open(LoggingHTTPConnection, req)

opener = urllib2.build_opener(LoggingHTTPHandler, ...)

--
Gabriel Genellina

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


Re: python function for retrieving key and encryption

2009-07-23 Thread jayshree
On Jul 21, 8:59 pm, Piet van Oostrum p...@cs.uu.nl wrote:
  jayshree jayshree06c...@gmail.com (j) wrote:
 j M2Crypto package not showing the 'recipient_public_key.pem' file at
 j linux terminal .how do i get/connect with recipient public key.
 j exactly i need to check how can i open this file through linux
 j commands.
 j import M2Crypto def encrypt(): recip = M2Crypto.RSA.load_pub_key(open
 j ('recipient_public_key.pem','rb').read()) print recip; plaintext =
 j whatever i need to encrypt msg = recip.public_encrypt
 j (plaintext,RSA.pkcs1_padding) print msg;
 j after calling the function its not giving any output and even any
 j error
 j i also tried as 'Will' said
 j pk = open('public_key.pem','rb').read() print pk; rsa =
 j M2Crypto.RSA.load_pub_key(pk)
 j whats the mistake i am not getting .will somebody help me out.
 j is something wrong in opening 'recipient_public_key.pem'. is M2Crypto
 j contain this file inbuilt .from where this file taking public key of
 j the recipient i'. what this file contain and how it will work .should
 j i need to create such a file for my purpose.if it is then how can i
 j create this  and how it will retrieve the key,where i recognize my
 j recipient to get his public key .is something like database at server.
 j please give me a quick response..
 j looking for your answer.

 Please:
 1. Type your python code with newlines and proper indentation.
 2. Show the error messages that your code gives when you run it.
 3. Use proper capital letters at the beginning of your sentences.
 4. Don't fire so many questions in rapid succession.

 The recipient_public_key.pem file is the public key of the recipient
 which means the person that is going to receive the encrypted message.
 You should get it from the recipient him/herself or from some key store
 where s/he has deposited it.
 --
 Piet van Oostrum p...@cs.uu.nl
 URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4]
 Private email: p...@vanoostrum.org- Hide quoted text -

 - Show quoted text -
Here is the code that i used

import M2Crypto
from M2Crypto import RSA

def encrypt():
recip = M2Crypto.RSA.load_pub_key(open
('recipient_public_key.pem','rb').read())
#recip = M2Crypto.RSA.load_pub_key('recipient_public_key.pem')
print recip;
plaintext = whatever i need to encrypt
msg = recip.public_encrypt(plaintext,RSA.pkcs1_padding)
print msg;


encrypt()


error coming like - IOError: [Errno 2] No such file or directory:
'recipient_public_key.pem'

Is this not the inbuilt file.
How should i create such type of file.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler

2009-07-23 Thread William Dode
On 23-07-2009, Kurt Smith wrote:
 On Wed, Jul 22, 2009 at 2:48 AM, Bearophilebearophileh...@lycos.com wrote:
 greg:
 Posting benchmark times for Pyrex or Cython is pretty
 meaningless without showing the exact code that was
 used, since times can vary enormously depending on
 how much you C-ify things.

 Was this link, shown by William, not enough?
 http://hg.flibuste.net/libre/games/cheval/file/46797c3a5136/chevalx.pyx#l1

 I took a stab at converting the recent psyco-optimized code to cython,
 and got a speedup.

thanks, i updated my repo with litle more tips.

-- 
William Dodé - http://flibuste.net
Informaticien Indépendant
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: binary literal

2009-07-23 Thread Hendrik van Rooyen
On Wednesday 22 July 2009 12:03:44 superpollo wrote:

 can i do something like the above, but using a *binary* number? (e.g.
 00101101 instead of 45) ?

00101101 is not hex 45.
hex 45 is 01000101

 chr(int('01000101',2))
'E'


- Hendrik



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


[Unblocking VoIP in UAE] for freedom!

2009-07-23 Thread cindy
Please view this newsletter online at:
http://www.mynewsletterbuilder.com/tools/view_newsletter.php?newsletter_id=1409985533
SpeedVoIP Communication Technology Co., LTD. - 600, 6th Avenue S.W. - Calgary
- Alberta - T2P 0S5

Subscribe to this newsletter:
https://www.mynewsletterbuilder.com/tools/subscription.php?username=svsalessend_id=712043215l=snewsletter_id=1409985533
Unsubscribe python-list@python.org:
https://www.mynewsletterbuilder.com/tools/subscription.php?username=svsalessend_id=712043215l=uemail=python-l...@python.org
Change your preferences:
https://www.mynewsletterbuilder.com/tools/subscription.php?username=svsalessend_id=712043215l=pemail=python-l...@python.org
Forward to a friend:
http://www.mynewsletterbuilder.com/tools/forward.php?username=svsalesnewsletter_id=1409985533email=python-l...@python.orgsend_id=712043215
Report this email as spam:
https://www.mynewsletterbuilder.com/tools/abuse_report.php?username=svsalessend_id=712043215email=python-l...@python.org

This email was sent using MyNewsletterBuilder.com.

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


Re: Changing the private variables content

2009-07-23 Thread Ethan Furman

Ryniek90 wrote:


Got it:

exec('self.' + attr + '=\'' + val + '\'')

That worked. I think it'll do what you want now ;)

Ching-Yun Xavier Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: cont...@xavierho.com mailto:cont...@xavierho.com
Website: http://xavierho.com/



To bad, that didn't worked in my class. Still the same error:

  mod.print_module('socket')

Traceback (most recent call last):
 File pyshell#121, line 1, in module
   mod.print_module('socket')
 File pyshell#118, line 51, in print_module
   module_open = open(self._this_module, 'rb')
IOError: [Errno 2] No such file or directory: ''
 


:-/


What is the point of the _SetVar method?

Instead of:

self._SetVar(self._this_module, os.path.join(root, f))

just do:

self._this_module = os.path.join(root, f)

(unless I'm misunderstanding what you're trying to do!)



Of course i;ve tried, but still get the same error:


  mod.print_module('socket')

Traceback (most recent call last):
 File pyshell#121, line 1, in module
   mod.print_module('socket')
 File pyshell#118, line 51, in print_module
   module_open = open(self.this_module, 'rb')
IOError: [Errno 2] No such file or directory: ''
 


It looks like private variable have specific naure, that prevent from 
traditional editing them.

Still searching for some tuts about private methods and variables.


No.  There is nothing special about variables with a leading underscore.

_number

is treated by Python *exactly* the same as

number

.  The specific problem in your code above is your _SetVar function, 
among the more general problem of not yet having a good understanding of 
classes in Python.  Keep studying, Python is an awesome language.


I was able to make this work -- hope it helps.

8---
import os
import sys

class ModPrint(object):
uThis will be the doc.
def __init__(self):
self._default_search_path = sys.exec_prefix

def _search_for_module(self, chosen_module, search_path):
for root, dirs, files in os.walk(search_path):
for f in files:
if f == (%s.py % chosen_module):
return os.path.join(root, f)

def print_module(self, chosen_module, user_search_path=''):
search_path = user_search_path or self._default_search_path
module = self._search_for_module(chosen_module, search_path)
if module is not None:
module_open = open(module, 'rb')
module_text = module_open.read()
module_open.close()
return module_text
return 'Module not found...'
8---
--
http://mail.python.org/mailman/listinfo/python-list


how two join and arrange two files together

2009-07-23 Thread amrita

Hi,

I have two large files:

FileA
15 ALA H = 8.05 N = 119.31 CA = 52.18 HA = 4.52 C =
21 ALA H = 7.66 N = 123.58 CA = 54.33 HA = C = 179.35
23 ALA H = 8.78 N =  CA =  HA = C = 179.93.

and

FileB
21 ALA  helix (helix_alpha, helix2)
23 ALA  helix (helix_alpha, helix3)
38 ALA  helix (helix_alpha, helix3)...

now what i want that i will make another file in which i will join the two
file in such a way that only matching entries will come like here 21 and
23 ALA is in both files, so the output will be something like:-

21 ALA H = 7.66 N = 123.58 CA = 54.33 HA = C = 179.35| 21 ALA  helix
(helix_alpha, helix2)
23 ALA H = 8.78 N =  CA =  HA = C = 179.93|23 ALA  helix (helix_alpha,
helix3)

and further i will make another file in which i will be able to put those
lines form this file based on the missing atom value, like for 21 ALA HA
is not defined so i will put it another file based on its HA missing value
similarly i will put 23 ALA on another file based on its missing N,CA and
HA value.

I tried to join the two file based on their matching entries by:---
from collections import defaultdict

 if __name__ == __main__:
...  a = open(/home/amrita/alachems/chem100.txt)
...  c = open(/home/amrita/secstr/secstr100.txt)
...
 def source(stream):
... return (line.strip() for line in stream)
...
...
 def merge(sources):
... for m in merge([source(a),source(c)]):
... print |.join(c.ljust(10) for c in m)
...

but it is not giving any value.






Thanks,
Amrita Kumari
Research Fellow
IISER Mohali
Chandigarh
INDIA

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


Re: Help understanding the decisions *behind* python?

2009-07-23 Thread Hendrik van Rooyen
On Wednesday 22 July 2009 16:36:51 Inky 788 wrote:
 On Jul 22, 2:36 am, Hendrik van Rooyen hend...@microcorp.co.za

 wrote:

  The good reason is the immutability, which lets you use
  a tuple as a dict key.  

 Thanks for the reply Hendrik (and Steven (other reply)). Perhaps I'm
 just not sophisticated enough, but I've never wanted to use a list/
 tuple as a dict key. This sounds like obscure usage, and a bit
 contrived as a reason for having *both* lists and tuples.

Steven showed why you cannot have a mutable thing
as a key in a dict.

if you think it is contrived, then please consider how you would 
keep track of say the colour of a pixel on a screen at position
(x,y) - this is about the simplest natural tuple format and
example.

There are other equally valid examples, as has been pointed
out.  (may have been in another thread - am a bit confused
about that right now)

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


Re: Ideas for problem with chat server application!

2009-07-23 Thread Martin P. Hellwig

David Adamo Jr. wrote:
cut

My
attempt was to create a windows service that start automatically and
runs this batch file using a Network Service account on the server
system. Although, I'm having a hard time with this (temporarily), I
would love to ask if there are any alternatives to using a windows
service. Suggestions are highly appreciated.


This is definitely the right way to go, perhaps reviewing a template 
which I use for windows services may help you:

http://blog.dcuktec.com/2009/07/python-windows-service-template.html

--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
--
http://mail.python.org/mailman/listinfo/python-list


Re: how two join and arrange two files together

2009-07-23 Thread Chris Rebert
On Thu, Jul 23, 2009 at 12:22 AM, amr...@iisermohali.ac.in wrote:

 Hi,

 I have two large files:

 FileA
 15 ALA H = 8.05 N = 119.31 CA = 52.18 HA = 4.52 C =
 21 ALA H = 7.66 N = 123.58 CA = 54.33 HA = C = 179.35
 23 ALA H = 8.78 N =  CA =  HA = C = 179.93.

 and

 FileB
 21 ALA  helix (helix_alpha, helix2)
 23 ALA  helix (helix_alpha, helix3)
 38 ALA  helix (helix_alpha, helix3)...

 now what i want that i will make another file in which i will join the two
 file in such a way that only matching entries will come like here 21 and
 23 ALA is in both files, so the output will be something like:-

 21 ALA H = 7.66 N = 123.58 CA = 54.33 HA = C = 179.35| 21 ALA  helix
 (helix_alpha, helix2)
 23 ALA H = 8.78 N =  CA =  HA = C = 179.93|23 ALA  helix (helix_alpha,
 helix3)

 and further i will make another file in which i will be able to put those
 lines form this file based on the missing atom value, like for 21 ALA HA
 is not defined so i will put it another file based on its HA missing value
 similarly i will put 23 ALA on another file based on its missing N,CA and
 HA value.

 I tried to join the two file based on their matching entries by:---
from collections import defaultdict

 if __name__ == __main__:
 ...      a = open(/home/amrita/alachems/chem100.txt)
 ...      c = open(/home/amrita/secstr/secstr100.txt)
 ...
 def source(stream):
 ...     return (line.strip() for line in stream)
 ...
 ...
 def merge(sources):
 ...     for m in merge([source(a),source(c)]):
 ...         print |.join(c.ljust(10) for c in m)
 ...

 but it is not giving any value.

You never actually called any of your expletive deleted functions.

Slightly corrected version:

from collections import defaultdict

def source(stream):
return (line.strip() for line in stream)

def merge(sources):
for m in sources:
print |.join(c.ljust(10) for c in m)

if __name__ == __main__:
a = open(/home/amrita/alachems/chem100.txt)
c = open(/home/amrita/secstr/secstr100.txt)
merge([source(a), source(c)])


It's still not sophisticated enough to give the exact output you're
looking for, but it is a step in the right direction.

You really should try asking someone from your CS Dept to help you. It
would seriously take a couple hours, at most.

- Chris
-- 
Still brandishing a cluestick a vain...
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: comments? storing a function in an object

2009-07-23 Thread Carl Banks
On Jul 22, 8:38 pm, a...@pythoncraft.com (Aahz) wrote:
 In article 
 f3d88edf-b5d3-43e4-89a3-b05ef0f55...@p28g2000vbn.googlegroups.com,
 Carl Banks  pavlovevide...@gmail.com wrote:

 You have to be REALLY REALLY careful not to pass any user-supplied
 data to it if this is a server running on your computer, of course.

 Unless, of course, your users are paying for this service.

Well, yes, but I assume that by the time you're deliberately letting
users pay to run their programs on your server, you will already have
deployed a full-blown, multi-tiered security strategy that includes
validation by the server process.  That was sort of beyond the scope
of the OP's question.


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


Re: PyQt GUI

2009-07-23 Thread Helvin
I believe I now have vtkpython.exe. However, my 'import vtk' statement
in my python code is not working. The error says something like no
module named vtk.
Where do I find modules for vtk in pyqt? Do they exist?

They must, right? Because there are people using vtk in pyqt? Or do I
have to use OpenGL?

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


Re: How to document Python code properly for Pydoc

2009-07-23 Thread jorma kala
Thanks very much for your help

On Wed, Jul 22, 2009 at 6:43 PM, Lie Ryan lie.1...@gmail.com wrote:

  jorma kala wrote:
  Hi,
  Do you know where I can find the rules for documenting Python code, so
  that automatic document generation with Pydoc makes the most of the
  comments inserted in the code?
  I know about documenting class and method through triple quote just
  under the class definition. But how do you comment a specific field or
  variable, or how do you document function arguments so that they are
  extracted like in javadoc?
  Thanks very much

 pydoc is a simple tool, and doesn't do much. You write in freeform,
 although generally you'll do something like this:

 def myfunc(a, b):
'''
short description of myfunc

longer description of myfunc, if necessary, and typically includes
description of the arguments and the behaviors. Also includes the
description of the return value.
'''

pass

 pydoc doesn't recognize any special markups. If you want to get more
 from the docstring, you need other documentation generator such as
 epydoc, Doxygen, or Sphinx.

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

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


Re: binary literal

2009-07-23 Thread superpollo

Hendrik van Rooyen wrote:

On Wednesday 22 July 2009 12:03:44 superpollo wrote:



can i do something like the above, but using a *binary* number? (e.g.
00101101 instead of 45) ?



00101101 is not hex 45.
hex 45 is 01000101



whoopsie daisie!




chr(int('01000101',2))


'E'



much obliged.

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


strange error when trying to log something

2009-07-23 Thread Ryszard Szopa
Hi,

I've recently reinstalled Python 2.6 (from DMG) on my Mac, and I am
running into very strage errors. Namely, logging seems to be badly
broken. When I open the interpreter through Django's manage.py shell
and try to use logging, I get the following error:

 logging.critical('ala')

Traceback (most recent call last):
  File ipython console, line 1, in module
  File /Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/logging/__init__.py, line 1416, in critical
root.critical(*((msg,)+args), **kwargs)
  File /Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/logging/__init__.py, line 1074, in critical
self._log(CRITICAL, msg, args, **kwargs)
  File /Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/logging/__init__.py, line 1142, in _log
record = self.makeRecord(self.name, level, fn, lno, msg, args,
exc_info, func, extra)
  File /Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/logging/__init__.py, line 1117, in makeRecord
rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
  File /Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/logging/__init__.py, line 272, in __init__
from multiprocessing import current_process
  File /Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/multiprocessing/__init__.py, line 64, in module
from multiprocessing.util import SUBDEBUG, SUBWARNING
  File /Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/multiprocessing/util.py, line 121, in module
_afterfork_registry = weakref.WeakValueDictionary()
  File /Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/weakref.py, line 51, in __init__
UserDict.UserDict.__init__(self, *args, **kw)
TypeError: unbound method __init__() must be called with UserDict
instance as first argument (got WeakValueDictionary instance instead)

I was able to silence the error (and be able to work normally) by
making UserDict.UserDict inherit from object.

Any ideas what is causing the error? Before I updated Python
everything was fine. Am I breaking a lot of things by making
UserDict.UserDict a new style class?

Thanks in advance for any insight.

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


Re: What is file.encoding convention?

2009-07-23 Thread Naoki INADA
 What is file.encoding convention?
 If I want to write a unicode string to a file(-like) that have
 encoding attribute, I should do
 (1) try: file.write(unicode_str),
 (2) except UnicodeEncodeError: file.write(unicode_str.encode
 (file.encoding))
 like logging?
 It seems agly.

s/agly/ugly/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strange error when trying to log something

2009-07-23 Thread Peter Otten
Ryszard Szopa wrote:

 Hi,
 
 I've recently reinstalled Python 2.6 (from DMG) on my Mac, and I am
 running into very strage errors. Namely, logging seems to be badly
 broken. When I open the interpreter through Django's manage.py shell
 and try to use logging, I get the following error:
 
 logging.critical('ala')
 
 Traceback (most recent call last):
   File ipython console, line 1, in module
   File /Library/Frameworks/Python.framework/Versions/2.6/lib/
 python2.6/logging/__init__.py, line 1416, in critical
 root.critical(*((msg,)+args), **kwargs)
   File /Library/Frameworks/Python.framework/Versions/2.6/lib/
 python2.6/logging/__init__.py, line 1074, in critical
 self._log(CRITICAL, msg, args, **kwargs)
   File /Library/Frameworks/Python.framework/Versions/2.6/lib/
 python2.6/logging/__init__.py, line 1142, in _log
 record = self.makeRecord(self.name, level, fn, lno, msg, args,
 exc_info, func, extra)
   File /Library/Frameworks/Python.framework/Versions/2.6/lib/
 python2.6/logging/__init__.py, line 1117, in makeRecord
 rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
   File /Library/Frameworks/Python.framework/Versions/2.6/lib/
 python2.6/logging/__init__.py, line 272, in __init__
 from multiprocessing import current_process
   File /Library/Frameworks/Python.framework/Versions/2.6/lib/
 python2.6/multiprocessing/__init__.py, line 64, in module
 from multiprocessing.util import SUBDEBUG, SUBWARNING
   File /Library/Frameworks/Python.framework/Versions/2.6/lib/
 python2.6/multiprocessing/util.py, line 121, in module
 _afterfork_registry = weakref.WeakValueDictionary()
   File /Library/Frameworks/Python.framework/Versions/2.6/lib/
 python2.6/weakref.py, line 51, in __init__
 UserDict.UserDict.__init__(self, *args, **kw)
 TypeError: unbound method __init__() must be called with UserDict
 instance as first argument (got WeakValueDictionary instance instead)
 
 I was able to silence the error (and be able to work normally) by
 making UserDict.UserDict inherit from object.
 
 Any ideas what is causing the error? Before I updated Python
 everything was fine. Am I breaking a lot of things by making
 UserDict.UserDict a new style class?
 
 Thanks in advance for any insight.
 
   -- Ryszard Szopa

I have a hunch that you are triggering a reload() somewhere. Example:

Python 2.6.2 (release26-maint, Apr 19 2009, 01:58:18)
[GCC 4.3.3] on linux2
Type help, copyright, credits or license for more information.
 import weakref
 weakref.WeakValueDictionary()
WeakValueDictionary at 140598938447312
 import UserDict
 reload(UserDict)
module 'UserDict' from '/usr/lib/python2.6/UserDict.pyc'
 weakref.WeakValueDictionary()
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/lib/python2.6/weakref.py, line 51, in __init__
UserDict.UserDict.__init__(self, *args, **kw)
TypeError: unbound method __init__() must be called with UserDict instance 
as first argument (got WeakValueDictionary instance instead)

Try restarting the interpreter after any change to source files.

Peter

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


Re: If Scheme is so good why MIT drops it?

2009-07-23 Thread Nobody
On Wed, 22 Jul 2009 15:17:52 -0700, Carl Banks wrote:

 So do all these OSes have some kind of __mega_unifying_poll system
 call that works for anything that might possibly block, that you can
 exploit from a user process?

Threads ;)

They also have the advantage that one thread can run while another is
waiting on disk I/O, which isn't something which can be done with a
select/poll interface (even if select/poll worked for files, it doesn't
help for mapped files).


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


Re: challenging problem for changing to a dedicated non-privileged user within a script.

2009-07-23 Thread Krishnakant
On Thu, 2009-07-23 at 00:17 +0200, Piet van Oostrum wrote:
 Being a sudoer is not a privilege to issue the os.setuid system call. It
 is only a permission to use the sudo command.
 
Yes, So I would like to know if python can change the user to some other
non-privileged user during the script execution?

 K I tryed using subprocess but that did not help me either.  I tryed sudo
 K su into the Popen command but it throws me into the terminal (shell)
 K with postgres as the user.
 
 You could execute the command:
 sudo -u postgres required_command
 with subprocess.
 
Ok, but the problem is much more complex.
What if I want to do the following.
1, change the user for a particular script to the postgres user.
2. now execute the python code for connecting to the postgresql
database.
In the second point I actually want to execute python code not shell
level command so will the sudo -u in the subprocess.Popen change the
user in the script?
In short I would just like to have the script run under another user
let's say postgres as long as a certain action is going on, for example
connecting to the postgresql database.

 
 You have another problem then: your password must be supplied unless the
 NOPASSWD flag is set in the sudoers file.
 
That is clear, the only problem is that I want the script to run as
postgres user although it was started by the user kk.


happy hacking.
Krishnakant.


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


available formats and params for Image.save()

2009-07-23 Thread News123
Hi,

Somehow I have difficulties reading the documentation for PIL (Image)

Is there an easy way to know which formats are supported and what their
names are?

Is there an easy way to know which parameters are supported by
Image.save(). How can I list them where are they documented?


Somehow I consider the documentation to be a little weak on this points.
all the documentation says (at least where I looked) is:

 class Image
  |  Methods defined here:
 . . .
  save(self, fp, format=None, **params)
  |  Save image to file or stream

In order to find out how the format name for a .jpg file I did following:

import Image
img = Image.open(afile.jpg)
print img.format


Then I saw, that the result was 'JPEG' and not 'JPG' as I tried first

I'm at a complete loss at finding out what parameters the save function
accepts for saving a JPG file or a PNG file

Is there an easy way of finding this in any doc or do I have to dive
into the sources.


If there's no easy way:
Wouldn't a better documentation increase the 'user experience'?



Thanks in advance for any pointers


N



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


Re: Multiple versions of python

2009-07-23 Thread Nobody
On Tue, 21 Jul 2009 10:19:42 -0400, Dave Angel wrote:

 The other thing you may want to do in a batch file is to change the file 
 associations so that you can run the .py file directly, without typing 
 python or pythonw in front of it.
 
 The relevant Windows commands are: assoc and ftype

However: assoc and ftype modify the registry keys under
HKLM\Software\Classes. This works fine if these are the only relevant
keys, but if you also have settings under HKCU\Software\Classes, those
will take precedence, so assoc and/or ftype won't have any effect.

Also, you typically need at least Power User status in order to modify
the keys under HKLM, while any user should be able to modify those under
HKCU (HKCU is a virtual key, corresponding to HKU\interactive user).

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


raster (PIL)

2009-07-23 Thread superpollo

hi.

i wrote a program which transforms a string of zeroes ando ones into a 
png file.


#!/usr/bin/env python
import Image
import sys
bits_in_a_byte = 8
raster_string = \

0010010000101000
00100100101010100100
00001110001010100100
00100100101010100100
0010010000000000


0010
10101001
1010
10101000
00001000


raster_lines = raster_string.splitlines()
high = len(raster_lines)
wide = len(raster_lines[0])
bytes_in_a_row = wide/bits_in_a_byte
bitmap = 
for raster_line in raster_lines:
for byte_count in range(bytes_in_a_row):
first_bit = byte_count*bits_in_a_byte
bitmap += 
chr(int(raster_line[first_bit:first_bit+bits_in_a_byte] , 2))

im = Image.fromstring(1, (wide , high) , bitmap)
im.save(sys.stdout , PNG)

any suggestions for improvement?

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


Re: Help understanding the decisions *behind* python?

2009-07-23 Thread Tim Rowe
2009/7/22 Inky 788 inky...@gmail.com:

 Thanks for the reply Hendrik (and Steven (other reply)). Perhaps I'm
 just not sophisticated enough, but I've never wanted to use a list/
 tuple as a dict key. This sounds like obscure usage, and a bit
 contrived as a reason for having *both* lists and tuples.

If you are used to working in a language that doesn't allow it then
you'll probably carry on using the work-arounds that you have always
used. It almost certainly only seems obscure because you're not
considering it when it would be a natural solution. In a language that
builds *very* heavily on the concept of dictionaries it's not obscure
at all!

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


Re: ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler

2009-07-23 Thread Nick Craig-Wood
srepmub mark.duf...@gmail.com wrote:
  please send any program that doesn't work with shedskin (it still is
  experimental after all) to me, or create an issue at
  shedskin.googlecode.com, and I will have a look at the problem.

I divided and conquered the program as suggested and eventually I got
it to compile and run correctly :-)

I learnt that if you have lots of variables with indeterminate type
then shedskin takes a very long time indeed before blowing up!

I also learnt that shedskin doesn't support the idiom I'd been using
for creating shallow copies, namely the Board.__new__(Board) below.
shedskin compiles it ok, but the C++ won't compile complaning about
not being able to find __init__ methods

Producing these warnings

*WARNING* rush_hour_solver_cut_down.py:71: class 'Vehicle' has no method 
'__new__'
*WARNING* rush_hour_solver_cut_down.py:72: variable 'new' has no type
*WARNING* rush_hour_solver_cut_down.py:236: variable 'new_vehicle' has no type

And these compile errors

rush_hour_solver_cut_down.cpp:94: error: ‘__new__’ is not a member of 
‘__rush_hour_solver_cut_down__::Vehicle’
rush_hour_solver_cut_down.cpp:95: error: expected type-specifier before ‘;’ 
token
rush_hour_solver_cut_down.cpp: In member function ‘void* 
__rush_hour_solver_cut_down__::Board::move(int, int)’:
rush_hour_solver_cut_down.cpp:276: error: ‘void*’ is not a pointer-to-object 
type
rush_hour_solver_cut_down.cpp:276: error: ‘void*’ is not a pointer-to-object 
type
rush_hour_solver_cut_down.cpp:279: error: ‘void*’ is not a pointer-to-object 
type
rush_hour_solver_cut_down.cpp:279: error: ‘void*’ is not a pointer-to-object 
type
rush_hour_solver_cut_down.cpp:281: error: invalid conversion from ‘void*’ to 
‘__rush_hour_solver_cut_down__::Vehicle*’


def copy(self):
new = Board.__new__(Board)
new.me_x = self.me_x
new.me_y = self.me_y
new.depth = self.depth
new.parent = self
new.best_child = None
new.board = [self.board[i][:] for i in range(WIDTH)]
new.rep = self.rep[:]
new.vehicles = self.vehicles[:]
return new

I changed to using copy.copy which did work, but I couldn't name my
copy methods copy otherwise I got this error from the C++ compile

rush_hour_solver_cut_down.cpp: In member function 
'__rush_hour_solver_cut_down__::Vehicle* 
__rush_hour_solver_cut_down__::Vehicle::copy()':
rush_hour_solver_cut_down.cpp:94: error: no matching function for call to 
'__rush_hour_solver_cut_down__::Vehicle::copy(__rush_hour_solver_cut_down__::Vehicle*
 const)'
rush_hour_solver_cut_down.cpp:89: note: candidates are: 
__rush_hour_solver_cut_down__::Vehicle* 
__rush_hour_solver_cut_down__::Vehicle::copy()
rush_hour_solver_cut_down.cpp: In member function 
'__rush_hour_solver_cut_down__::Board* 
__rush_hour_solver_cut_down__::Board::copy()':
rush_hour_solver_cut_down.cpp:135: error: no matching function for call to 
'__rush_hour_solver_cut_down__::Board::copy(__rush_hour_solver_cut_down__::Board*
 const)'
rush_hour_solver_cut_down.cpp:129: note: candidates are: 
__rush_hour_solver_cut_down__::Board* 
__rush_hour_solver_cut_down__::Board::copy()

So I renamed them to pycopy, and they ended up looking like

def pycopy(self):
new = copy(self)
new.parent = self
new.best_child = None
new.board = [self.board[i][:] for i in range(WIDTH)]
new.rep = self.rep[:]
new.vehicles = self.vehicles[:]
return new

After all that - some timing results!

Python:   9.3 seconds
Psyco:5.8 seconds
ShedSkin: 1.0 seconds

Impressive!

I put the code http://www.craig-wood.com/nick/pub/rush_hour_solver_cut_down.py

I left in the commented out bits of code I had to change.

This is only part of the project (375 lines) - it solves Rush Hour
boards.  There is another part which I haven't attempted to compile
yet which finds the most difficult possible boards using a combination
of back tracking and a genetic algorithm.

-- 
Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


sqlite3 performance problems only in python

2009-07-23 Thread Stef Mientki

hello,

until now I used only small / simple databases in Python with sqlite3.
Now I've a large and rather complex database.

The most simple query (with just a result of 100 rows),
takes about 70 seconds.
And all that time is consumed in cursor.fetchall

Using the same database in Delphi,
using the same query,
takes less than 5 seconds (including displaying the full table in a grid).

Are there in Python faster ways to get the query results ?
Would it be faster if I used an ODBC coupling and PyODBC to interface 
the database ?


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


Re: challenging problem for changing to a dedicated non-privileged user within a script.

2009-07-23 Thread paul

Krishnakant schrieb:

On Thu, 2009-07-23 at 00:17 +0200, Piet van Oostrum wrote:

Being a sudoer is not a privilege to issue the os.setuid system call. It
is only a permission to use the sudo command.


Yes, So I would like to know if python can change the user to some other
non-privileged user during the script execution?

If the user running python program is allowed to call setuid() then yes.




K I tryed using subprocess but that did not help me either.  I tryed sudo
K su into the Popen command but it throws me into the terminal (shell)
K with postgres as the user.

You could execute the command:
sudo -u postgres required_command
with subprocess.


Ok, but the problem is much more complex.

No.


What if I want to do the following.
1, change the user for a particular script to the postgres user.

Did you try running sudo -u postgres blabla with subprocess?


2. now execute the python code for connecting to the postgresql
database.
In the second point I actually want to execute python code not shell
level command so will the sudo -u in the subprocess.Popen change the
user in the script?
No, as the name subprocess suggests you are spawning a new process 
which gets another uid through sudo. This does not affect the parent 
process.


hth
 Paul


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


Re: raster (PIL)

2009-07-23 Thread Diez B. Roggisch
superpollo wrote:

 hi.
 
 i wrote a program which transforms a string of zeroes ando ones into a
 png file.
 
 #!/usr/bin/env python
 import Image
 import sys
 bits_in_a_byte = 8
 raster_string = \
 
 0010010000101000
 00100100101010100100
 00001110001010100100
 00100100101010100100
 0010010000000000
 
 
 0010
 10101001
 1010
 10101000
 00001000
 
 
 raster_lines = raster_string.splitlines()
 high = len(raster_lines)
 wide = len(raster_lines[0])
 bytes_in_a_row = wide/bits_in_a_byte

This will give you the wrong result if not divideable by bits_in_a_byte. 

 bitmap = 
 for raster_line in raster_lines:
  for byte_count in range(bytes_in_a_row):
  first_bit = byte_count*bits_in_a_byte
  bitmap +=
 chr(int(raster_line[first_bit:first_bit+bits_in_a_byte] , 2))
 im = Image.fromstring(1, (wide , high) , bitmap)
 im.save(sys.stdout , PNG)
 
 any suggestions for improvement?

Instead of 

res = 
for ...:
res += ...

use 

res = []
for ...:
res.append(...)

.join(res)

There are some optimizations for the +=-op on strings, but I'm not sure how
far they go, and the other form is safer.

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


Re: Copy/paste through LAN

2009-07-23 Thread Piet van Oostrum
 Jun junh...@gmail.com (J) wrote:

J Hello,
J I've a client/server application which uses Pyro to communicate each
J other.
J Now i try to implement copy/paste through LAN between server
J controlled
J filesystem to my local windows machine (I could list files in client's
J window).
J How can i pass the url information through Pyro ?

What do you mean? Do you want to copy a file or copy file names? Copying
a file between two machines can best be done by a specialized protocol,
like HTTP or scp. Pasting a file doesn't make sense IMHO.

And URLs are just strings.
-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: challenging problem for changing to a dedicated non-privileged user within a script.

2009-07-23 Thread Piet van Oostrum
 Krishnakant hackin...@gmail.com (K) wrote:

K On Thu, 2009-07-23 at 00:17 +0200, Piet van Oostrum wrote:
 Being a sudoer is not a privilege to issue the os.setuid system call. It
 is only a permission to use the sudo command.
 
K Yes, So I would like to know if python can change the user to some other
K non-privileged user during the script execution?

As I said you can't (unless you are root). It would be a security leak if
an arbitrary user could suddenly run as another user. Sudo is the escape
mechanism but it runs commands, and is not for changing the uid in the
middle of a process.

 K I tryed using subprocess but that did not help me either.  I tryed sudo
 K su into the Popen command but it throws me into the terminal (shell)
 K with postgres as the user.
 
 You could execute the command:
 sudo -u postgres required_command
 with subprocess.
 
K Ok, but the problem is much more complex.
K What if I want to do the following.
K 1, change the user for a particular script to the postgres user.
K 2. now execute the python code for connecting to the postgresql
K database.
K In the second point I actually want to execute python code not shell
K level command so will the sudo -u in the subprocess.Popen change the
K user in the script?

You can run another python script as the other user (o even the same
python script). You said you tried subprocess. If that is acceptable
then running another python script should also be acceptable, becaus eit
is basically the same.

K In short I would just like to have the script run under another user
K let's say postgres as long as a certain action is going on, for example
K connecting to the postgresql database.

Why would you have to be another user for connecting to a postgres
database? The DBMS takes care of the permissions at the DB level.

Otherwise you would have to do the DB access in another script. The
script could even communicate withe the original script, e.g by pipes or
some protocol like XMLRPC.
-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: challenging problem for changing to a dedicated non-privileged user within a script.

2009-07-23 Thread Krishnakant
On Thu, 2009-07-23 at 13:50 +0200, paul wrote:

 If the user running python program is allowed to call setuid() then yes.
 
NO, i don't think i can do that.  I am getting opperation not permitted.

Any ways I think probably subprocess will have to sort it out.

 Did you try running sudo -u postgres blabla with subprocess?
 
Yes, but still not got the intended result which is now obvious.
  2. now execute the python code for connecting to the postgresql
  database.
  In the second point I actually want to execute python code not shell
  level command so will the sudo -u in the subprocess.Popen change the
  user in the script?
 No, as the name subprocess suggests you are spawning a new process 
 which gets another uid through sudo. This does not affect the parent 
 process.
 
Ok then here is the work-around which I am thinking to try, Plese tell
me if it is correct.
I will let that subprocess start python inthe background and execute the
connecting code to postgresql including importing the pygresql library.
Then I will create the connection and cursor objcts in that subprocess.
But my concern is, will the connection object in the child process
(subprocess) be available to the parrent process?


happy hacking.
Krishnakant.


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


Re: how two join and arrange two files together

2009-07-23 Thread Jyoti Sharma

On Thu, 23 Jul 2009 12:52:15 +0530, amr...@iisermohali.ac.in wrote:



Hi,

I have two large files:

FileA
15 ALA H = 8.05 N = 119.31 CA = 52.18 HA = 4.52 C =
21 ALA H = 7.66 N = 123.58 CA = 54.33 HA = C = 179.35
23 ALA H = 8.78 N =  CA =  HA = C = 179.93.

and

FileB
21 ALA  helix (helix_alpha, helix2)
23 ALA  helix (helix_alpha, helix3)
38 ALA  helix (helix_alpha, helix3)...

now what i want that i will make another file in which i will join the  
two

file in such a way that only matching entries will come like here 21 and
23 ALA is in both files, so the output will be something like:-

21 ALA H = 7.66 N = 123.58 CA = 54.33 HA = C = 179.35| 21 ALA  helix
(helix_alpha, helix2)
23 ALA H = 8.78 N =  CA =  HA = C = 179.93|23 ALA  helix (helix_alpha,
helix3)

and further i will make another file in which i will be able to put those
lines form this file based on the missing atom value, like for 21 ALA HA
is not defined so i will put it another file based on its HA missing  
value

similarly i will put 23 ALA on another file based on its missing N,CA and
HA value.

I tried to join the two file based on their matching entries by:---


(snip)

I believe there are packages available for doing such things mostly  
written in perl. But if the aim is not to develop suitable applications  
but only to obtain the desired formatted file then doing this with the  
help of something like Excel would be easiest. This is my opinion from the  
experience I have from my bioinfo programming.


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


Looking for os.listdir() generator

2009-07-23 Thread Christian Heimes
Hello,

I'm looking for a generator version of os.listdir() for Python 2.5 and
newer. I know somebody has worked on it because I've seen a generator
version in a posting on some list or blog a while ago. I can't find it
anymore. It seems my Google fu is lacking today. All I can find is a
very old version of xlistdir. A Cython based solution is appreciated but
please no ctypes version.

Christian

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


Re: sqlite3 performance problems only in python

2009-07-23 Thread Tim Chase

until now I used only small / simple databases in Python with sqlite3.
Now I've a large and rather complex database.

The most simple query (with just a result of 100 rows),
takes about 70 seconds.
And all that time is consumed in cursor.fetchall

Using the same database in Delphi,
using the same query,
takes less than 5 seconds (including displaying the full table in a grid).


While it may seem obvious, are you doing anything time-consuming 
with those results?  Or have you tested just doing the fetchall() 
without doing any further processing?  I'm curious on the timing of


  sql = ...
  start = time()
  cursor.execute(sql)
  rows = cursor.fetchall()
  end = time()
  print end-start

with no other processing.  I regularly write sql that's fairly 
complex and brings back somewhat large datasets (sometimes in 
sqlite), and have never experienced problems with simple 
quer[ies] (with just a result of 100 rows taking such 
extrordinary times


The answer from the above code will help determine whether it's 
the sqlite portion that's crazy (and might need some well-placed 
index statements; though if your Delphi code is fine, I suspect 
not), or if it's your application code that goes off into left 
field with the resulting data.


-tkc




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


Re: raster (PIL)

2009-07-23 Thread Peter Otten
superpollo wrote:

 i wrote a program which transforms a string of zeroes ando ones into a
 png file.
 
 #!/usr/bin/env python
 import Image
 import sys
 bits_in_a_byte = 8
 raster_string = \
 
 0010010000101000
 00100100101010100100
 00001110001010100100
 00100100101010100100
 0010010000000000
 
 
 0010
 10101001
 1010
 10101000
 00001000
 
 
 raster_lines = raster_string.splitlines()
 high = len(raster_lines)
 wide = len(raster_lines[0])
 bytes_in_a_row = wide/bits_in_a_byte
 bitmap = 
 for raster_line in raster_lines:
  for byte_count in range(bytes_in_a_row):
  first_bit = byte_count*bits_in_a_byte
  bitmap +=
 chr(int(raster_line[first_bit:first_bit+bits_in_a_byte] , 2))
 im = Image.fromstring(1, (wide , high) , bitmap)
 im.save(sys.stdout , PNG)
 
 any suggestions for improvement?

You can simplify the inner loop:

for first_bit in range(0, wide, bits_in_a_byte):
bitmap += ...

and get rid of a few helper variables.

Here's a different approach:

#!/usr/bin/env python
import Image
import string
import sys

mapping = string.maketrans(01, \x00\xff)

raster_string = ...

width = raster_string.index(\n)
height = raster_string.count(\n)

raster_string = raster_string.translate(mapping, \n)

im = Image.fromstring(L, (width, height), raster_string)
im.convert(1).save(sys.stdout, PNG)

The idea is to move the bit-twiddling from python to code written in C, 
pointless for such a tiny picture but crucial for the performance when you 
want to manipulate larger images.

Peter

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


Re: raster (PIL)

2009-07-23 Thread superpollo

Diez B. Roggisch wrote:

superpollo wrote:

...

high = len(raster_lines)
wide = len(raster_lines[0])
bytes_in_a_row = wide/bits_in_a_byte



This will give you the wrong result if not divideable by bits_in_a_byte. 



then maybe:

#!/usr/bin/env python
import Image
import sys
bits_in_a_byte = 8
raster_string = \
00
0010010000101000
00100100101010100100
00001110001010100100
00100100101010100100
0010010000000000


0010
10101001
1010
10101000
00001000


raster_lines = raster_string.splitlines()
high = len(raster_lines)
wide = len(raster_lines[0])
bytes_in_a_row = wide/bits_in_a_byte
wide_for_real = bytes_in_a_row*bits_in_a_byte
if wide_for_real:
bitmap = 
for raster_line in raster_lines:
for byte_count in range(bytes_in_a_row):
first_bit = byte_count*bits_in_a_byte
bitmap += 
chr(int(raster_line[first_bit:first_bit+bits_in_a_byte] ,

2))
im = Image.fromstring(1, (wide_for_real , high) , bitmap)
im.save(sys.stdout , PNG)

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


Re: python function for retrieving key and encryption

2009-07-23 Thread Piet van Oostrum
 jayshree jayshree06c...@gmail.com (j) wrote:

j On Jul 21, 8:59 pm, Piet van Oostrum p...@cs.uu.nl wrote:

 The recipient_public_key.pem file is the public key of the recipient
 which means the person that is going to receive the encrypted message.
 You should get it from the recipient him/herself or from some key store
 where s/he has deposited it.
[...]

j error coming like - IOError: [Errno 2] No such file or directory:
j 'recipient_public_key.pem'

j Is this not the inbuilt file.
j How should i create such type of file.

You don't create it. See above. If you understand what is is you know
why it can't be builtin. If you don't understand it is better if you
first learn about OpenSSL, otherwise you run the risk to make serious
errors. 

If you are just experimenting to create a message for yourself then you
have to create the public key because you are then the recipient
yourself. That has been answered on
http://stackoverflow.com/questions/1169798/m2crypto-package 
-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: raster (PIL)

2009-07-23 Thread superpollo

Peter Otten wrote:

superpollo wrote:



i wrote a program which transforms a string of zeroes ando ones into a
png file.

...

any suggestions for improvement?

...

Here's a different approach:

...
The idea is to move the bit-twiddling from python to code written in C, 
pointless for such a tiny picture but crucial for the performance when you 
want to manipulate larger images.


very very interesting... you know i come from a lower level language 
approach (C/Pascal) so i find it difficult (but full of fascination) to 
adapt to such a different and much simpler way of thinking.


anyways, thanks a lot.

bye

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


Re: sqlite3 performance problems only in python

2009-07-23 Thread Stef Mientki

Tim Chase wrote:

until now I used only small / simple databases in Python with sqlite3.
Now I've a large and rather complex database.

The most simple query (with just a result of 100 rows),
takes about 70 seconds.
And all that time is consumed in cursor.fetchall

Using the same database in Delphi,
using the same query,
takes less than 5 seconds (including displaying the full table in a 
grid).


While it may seem obvious, are you doing anything time-consuming with 
those results?  Or have you tested just doing the fetchall() without 
doing any further processing?  I'm curious on the timing of


  sql = ...
  start = time()
  cursor.execute(sql)
  rows = cursor.fetchall()
  end = time()
  print end-start

No this is exactly what I did,
I timed the execute and fetchall seperatly:
execute: 125 msec
fetchall: 71000 msec  (returning 100 rows and 25 columns)
pysqlite:  version 2.3.2

btw, I don't know if it's of any importance, the SQL-statement I perform is
select OPNAMEN.*, NAME, NAME_, SCORES.SCORE, PATIENT.*
 from OPNAMEN
   inner join POID_VLID  on OPNAMEN.POID= 
POID_VLID.POID
   inner join VRAAGLST   on VRAAGLST.VLID   = 
POID_VLID.VLID
   inner join VLID_SSID  on VRAAGLST.VLID   = 
VLID_SSID.VLID
   inner join SUBSCHAAL_GEGEVENS on SUBSCHAAL_GEGEVENS.SSID = 
VLID_SSID.SSID
   inner join POID_SSID_SCID on ( OPNAMEN.POID= 
POID_SSID_SCID.POID ) and
( SUBSCHAAL_GEGEVENS.SSID = 
POID_SSID_SCID.SSID )
   inner join SCORES on SCORES.SCID = 
POID_SSID_SCID.SCID

   inner join PID_POID   on OPNAMEN.POID= PID_POID.POID
   inner join PATIENTon PATIENT.PID = PID_POID.PID
 where substr ( lower( NAME) , 1, 6)  = 'cis20r'
   and lower ( NAME_ ) = 'fatigue'
   and TEST_COUNT in (3,4)
   and DATETIME  39814.0
   and SCORE  30

cheers,
Stef



with no other processing.  I regularly write sql that's fairly complex 
and brings back somewhat large datasets (sometimes in sqlite), and 
have never experienced problems with simple quer[ies] (with just a 
result of 100 rows taking such extrordinary times


The answer from the above code will help determine whether it's the 
sqlite portion that's crazy (and might need some well-placed index 
statements; though if your Delphi code is fine, I suspect not), or if 
it's your application code that goes off into left field with the 
resulting data.


-tkc






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


Re: Pyserial and pyQt

2009-07-23 Thread Robert Franke
On Tue, Jul 21, 2009 at 9:37 PM, Seth king.s...@gmail.com wrote:


 I have used pyserial in the past but this is my first experience with
 pyQt.  I am using the Python xy package for windows current but might
 move to linux.  I have a small device that is outputting a basic text
 string.  I want to be able to read this string(from the comm port) and
 update a text box and eventually a graph in pyQt.  I can't find any
 documentation or tutorials on how to do this.  If anyone can point me
 in the right direction or give me some tips I would be grateful.



As I need to do something similar I looked around and found the following
recipe at activestate:

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

In the comments there is an example for PyQt.


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


Re: raster (PIL)

2009-07-23 Thread superpollo

Peter Otten wrote:
...

Here's a different approach:

...

raster_string = ...

width = raster_string.index(\n)
height = raster_string.count(\n)


your approach has a funny side-effect: try to remove just one zero from 
the first line of the raster ;-)


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


Re: raster (PIL)

2009-07-23 Thread superpollo

Peter Otten wrote:
...

im.convert(1).save(sys.stdout, PNG)

...

a q about pil:

im.convert(1)

is different from:

im2 = im.convert(1)

right?

in the former im is changed (the method applies to im) but in the latter 
im is unchanged (first im is copied unto im2 and then the method is 
applied to im2)... am i right?


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


Re: Detect target name in descriptor __set__ method

2009-07-23 Thread DG
On Jul 22, 6:05 pm, Gabriel Genellina gagsl-...@yahoo.com.ar
wrote:
 En Wed, 22 Jul 2009 11:01:09 -0300, Rhodri James  
 rho...@wildebst.demon.co.uk escribió:

  On Wed, 22 Jul 2009 06:02:55 +0100, Gabriel Genellina  
  gagsl-...@yahoo.com.ar wrote:

  class X(object):
     foo = descriptor()

  x = X()
  x.foo = value

  Isn't this going to create a brand new instance attribute x.foo that has  
  nothing to do with the descriptor anyway?

 No, it's up to the descriptor __set__ method what happens in this case.  
 Think of the standard 'property' descriptor, the fset function can do  
 whatever it wants.
 Also, a data descriptor takes precedence over any instance attribute of  
 the same name that might exist.

 --
 Gabriel Genellin

You might've already thought of this (and it is annoying), but you
could pass the name through the descriptor's init method.  I believe
this is the only way besides assigning a metaclass that will look for
that type of descriptor upon class creation and set the descriptor's
name at that time.

class A(object):
def __init__(self, attr_name):
self._name = attr_name
def __set__(self, instance, value):
self.instance.__dict__[self._name] = value
# or something like that...

class B(object):
foo = A('foo')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regex: multiple matching for one string

2009-07-23 Thread Mark Lawrence

scriptlear...@gmail.com wrote:

For example, I have a string #a=valuea;b=valueb;c=valuec;, and I
will like to take out the values (valuea, valueb, and valuec).  How do
I do that in Python?  The group method will only return the matched
part.  Thanks.

p = re.compile('#a=*;b=*;c=*;')
m = p.match(line)
if m:
 print m.group(),


IMHO a regex for this is overkill, a combination of string methods such 
as split and find should suffice.


Regards.

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


Re: raster (PIL)

2009-07-23 Thread Diez B. Roggisch
superpollo wrote:

 Diez B. Roggisch wrote:
 superpollo wrote:
 ...
high = len(raster_lines)
wide = len(raster_lines[0])
bytes_in_a_row = wide/bits_in_a_byte
 
 
 This will give you the wrong result if not divideable by bits_in_a_byte.
 
 
 then maybe:
 
 #!/usr/bin/env python
 import Image
 import sys
 bits_in_a_byte = 8
 raster_string = \
 00
 0010010000101000
 00100100101010100100
 00001110001010100100
 00100100101010100100
 0010010000000000
 
 
 0010
 10101001
 1010
 10101000
 00001000
 
 
 raster_lines = raster_string.splitlines()
 high = len(raster_lines)
 wide = len(raster_lines[0])
 bytes_in_a_row = wide/bits_in_a_byte
 wide_for_real = bytes_in_a_row*bits_in_a_byte

No. Because that would skip up to 7 bits.

Instead, do

bytes_in_a_row = wide/bits_in_a_byte
if wide % bits_in_a_byte:
   bytes_in_a_row += 1

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


Re: Predefined Variables

2009-07-23 Thread Diez B. Roggisch
Fred Atkinson wrote:

 Is there a pre-defined variable that returns the GET line
 (http://www.php.net/index.php?everythingafterthequestionmark) as a
 single variable (rather than individual variables)?

Variables don't return things. Functions do. And additionally the answer
depends on what and with what you actually do.

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


Re: challenging problem for changing to a dedicated non-privileged user within a script.

2009-07-23 Thread paul

Krishnakant schrieb:

On Thu, 2009-07-23 at 13:50 +0200, paul wrote:


If the user running python program is allowed to call setuid() then yes.


NO, i don't think i can do that.  I am getting opperation not permitted.

Any ways I think probably subprocess will have to sort it out.


Did you try running sudo -u postgres blabla with subprocess?


Yes, but still not got the intended result which is now obvious.

Why is that obvious? Works for me:

 test.py -
#!/usr/bin/python

from subprocess import Popen, PIPE

cmd = Popen('sudo -u vboxadd /home/pkoelle/Documents/whoami.sh', 
shell=True, stdout=PIPE, stderr=PIPE)

print OUT: +cmd.stdout.read()
print ERR: +cmd.stderr.read()

 whoami.sh -
#!/bin/bash
echo $UID
logger whoami script called for $UID

Of course, you need to adapt path and user values to your situation. The 
user you use in your 'sudo -u user...' call needs execute permissions 
for whoami.sh. The relevant entry in /etc/sudoers:


pkoelle ALL=NOPASSWD: /home/pkoelle/Documents/whoami.sh

hth
 Paul

PS: This has absolutely nothing to do with connecting to postgresql. A 
postgres user is not a system user (Piet already asked the right 
questions here ;)




2. now execute the python code for connecting to the postgresql
database.
In the second point I actually want to execute python code not shell
level command so will the sudo -u in the subprocess.Popen change the
user in the script?
No, as the name subprocess suggests you are spawning a new process 
which gets another uid through sudo. This does not affect the parent 
process.



Ok then here is the work-around which I am thinking to try, Plese tell
me if it is correct.
I will let that subprocess start python inthe background and execute the
connecting code to postgresql including importing the pygresql library.
Then I will create the connection and cursor objcts in that subprocess.
But my concern is, will the connection object in the child process
(subprocess) be available to the parrent process?


happy hacking.
Krishnakant.




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


Re: raster (PIL)

2009-07-23 Thread Peter Otten
superpollo wrote:

 Peter Otten wrote:
 ...
 im.convert(1).save(sys.stdout, PNG)
 ...
 
 a q about pil:
 
 im.convert(1)
 
 is different from:
 
 im2 = im.convert(1)
 
 right?
 
 in the former im is changed (the method applies to im) but in the latter
 im is unchanged (first im is copied unto im2 and then the method is
 applied to im2)... am i right?

No. A method has no clue whether its result is used or discarded. Therefore

im.convert(1)

creates a new image in the specified mode, too, which is discarded 
immediately. If you don't need the result you probably shouldn't call the 
method at all.

Peter


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


Re: raster (PIL)

2009-07-23 Thread superpollo

Peter Otten wrote:

superpollo wrote:



Peter Otten wrote:
...


im.convert(1).save(sys.stdout, PNG)


...

a q about pil:

im.convert(1)

is different from:

im2 = im.convert(1)

right?

in the former im is changed (the method applies to im) but in the latter
im is unchanged (first im is copied unto im2 and then the method is
applied to im2)... am i right?



No. A method has no clue whether its result is used or discarded. Therefore

im.convert(1)

creates a new image in the specified mode, too, which is discarded 
immediately.


but in:

im.convert(1).save(sys.stdout, PNG)

the new (anonymous) image created by .convert is not discarded 
*immediately*, i mean *before* the .save method is called on it, right?


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


Re: JavaScript toolkits (was Re: ANN: Porcupine Web Application Server 0.6 is released!)

2009-07-23 Thread Paul Boddie
On 23 Jul, 05:55, a...@pythoncraft.com (Aahz) wrote:
 In article 
 1c994086-8c58-488f-b3b3-6161c4b2b...@k30g2000yqf.googlegroups.com,
 Paul Boddie  p...@boddie.org.uk wrote:

 http://www.boddie.org.uk/python/XSLTools.html

 Thanks!  I'll take a look after OSCON.

The JavaScript parts of the framework are a bit complicated, I'll
admit: you have to write some nasty-looking function calls with
awkward arguments to send AJAX-style requests to the server. I've been
meaning to employ a more declarative signals and slots approach so
that you don't have to write in the page templates where the in-page
updates should be expected: it's really the server code that
determines this kind of thing, and so the server code should be able
to say where it wants the page to be updated.

Again, I'll try and put up some examples in the relatively near future
that will make it easier for you to see if it's your kind of thing.

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


Re: raster (PIL)

2009-07-23 Thread Peter Otten
superpollo wrote:

 Peter Otten wrote:
 superpollo wrote:
 
 
Peter Otten wrote:
...

im.convert(1).save(sys.stdout, PNG)

...

a q about pil:

im.convert(1)

is different from:

im2 = im.convert(1)

right?

in the former im is changed (the method applies to im) but in the latter
im is unchanged (first im is copied unto im2 and then the method is
applied to im2)... am i right?
 
 
 No. A method has no clue whether its result is used or discarded.
 Therefore
 
 im.convert(1)
 
 creates a new image in the specified mode, too, which is discarded
 immediately.
 
 but in:
 
 im.convert(1).save(sys.stdout, PNG)
 
 the new (anonymous) image created by .convert is not discarded
 *immediately*, i mean *before* the .save method is called on it, right?

Of course. Think of it as a shortcut for

tmp = im.convert(...)
tmp.save(...)
del tmp

Peter


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


Re: how two join and arrange two files together

2009-07-23 Thread amrita
I tried to print those lines having C value missing by:

import re
expr = re.compile(C = None)
f = open(/home/amrita/helix.dat)
for line in f:
if expr.search(line):
   print line

but it is not giving any value.


 Hi,

 I have two large files:

 FileA
 15 ALA H = 8.05   N = 119.31 CA = 52.18 HA = 4.52 C =
 21 ALA H = 7.66   N = 123.58 CA = 54.33 HA = C = 179.35
 23 ALA H = 8.78   N =  CA =  HA = C = 179.93.

 and

 FileB
 21 ALA  helix (helix_alpha, helix2)
 23 ALA  helix (helix_alpha, helix3)
 38 ALA  helix (helix_alpha, helix3)...

 now what i want that i will make another file in which i will join the two
 file in such a way that only matching entries will come like here 21 and
 23 ALA is in both files, so the output will be something like:-

 21 ALA H = 7.66   N = 123.58 CA = 54.33 HA = C = 179.35| 21 ALA  helix
 (helix_alpha, helix2)
 23 ALA H = 8.78   N =  CA =  HA = C = 179.93|23 ALA  helix (helix_alpha,
 helix3)

 and further i will make another file in which i will be able to put those
 lines form this file based on the missing atom value, like for 21 ALA HA
 is not defined so i will put it another file based on its HA missing value
 similarly i will put 23 ALA on another file based on its missing N,CA and
 HA value.

 I tried to join the two file based on their matching entries by:---
from collections import defaultdict

 if __name__ == __main__:
 ...  a = open(/home/amrita/alachems/chem100.txt)
 ...  c = open(/home/amrita/secstr/secstr100.txt)
 ...
 def source(stream):
 ... return (line.strip() for line in stream)
 ...
 ...
 def merge(sources):
 ... for m in merge([source(a),source(c)]):
 ... print |.join(c.ljust(10) for c in m)
 ...

 but it is not giving any value.






 Thanks,
 Amrita Kumari
 Research Fellow
 IISER Mohali
 Chandigarh
 INDIA



Amrita Kumari
Research Fellow
IISER Mohali
Chandigarh
INDIA

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


Re: Detect target name in descriptor __set__ method

2009-07-23 Thread DG
On Jul 23, 7:19 am, DG dang...@gmail.com wrote:
 On Jul 22, 6:05 pm, Gabriel Genellina gagsl-...@yahoo.com.ar
 wrote:



  En Wed, 22 Jul 2009 11:01:09 -0300, Rhodri James  
  rho...@wildebst.demon.co.uk escribió:

   On Wed, 22 Jul 2009 06:02:55 +0100, Gabriel Genellina  
   gagsl-...@yahoo.com.ar wrote:

   class X(object):
      foo = descriptor()

   x = X()
   x.foo = value

   Isn't this going to create a brand new instance attribute x.foo that has  
   nothing to do with the descriptor anyway?

  No, it's up to the descriptor __set__ method what happens in this case.  
  Think of the standard 'property' descriptor, the fset function can do  
  whatever it wants.
  Also, a data descriptor takes precedence over any instance attribute of  
  the same name that might exist.

  --
  Gabriel Genellin

 You might've already thought of this (and it is annoying), but you
 could pass the name through the descriptor's init method.  I believe
 this is the only way besides assigning a metaclass that will look for
 that type of descriptor upon class creation and set the descriptor's
 name at that time.

 class A(object):
     def __init__(self, attr_name):
         self._name = attr_name
     def __set__(self, instance, value):
         self.instance.__dict__[self._name] = value
         # or something like that...

 class B(object):
     foo = A('foo')

Well of course I think of more alternatives after I post.
1) still annoying... pass the class through a 'registering' function
that will examine all of it's attrs and find the ones that are of your
descriptor type, and assign the attr_name upon that descriptor.name
attribute.

2) I just thought of, and it's kind of a hack is to do this
examination within the '__set__' method.
e.g.

class A(object):
def __get__(self, instance, owner):
if instance is None:
return self
else:
# do something different here for instances' access
return self

def __set__(self, instance, value):
cls = instance.__class__
name = None
for attr in dir(cls):
if getattr(cls, attr) is self:
name = attr
print name
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Detect target name in descriptor __set__ method

2009-07-23 Thread Rhodri James
On Thu, 23 Jul 2009 01:05:55 +0100, Gabriel Genellina  
gagsl-...@yahoo.com.ar wrote:


En Wed, 22 Jul 2009 11:01:09 -0300, Rhodri James  
rho...@wildebst.demon.co.uk escribió:
On Wed, 22 Jul 2009 06:02:55 +0100, Gabriel Genellina  
gagsl-...@yahoo.com.ar wrote:




class X(object):
   foo = descriptor()

x = X()
x.foo = value


Isn't this going to create a brand new instance attribute x.foo that  
has nothing to do with the descriptor anyway?


No, it's up to the descriptor __set__ method what happens in this case.  
Think of the standard 'property' descriptor, the fset function can do  
whatever it wants.


If it gets called, that is.

Also, a data descriptor takes precedence over any instance attribute of  
the same name that might exist.


This was the bit I wasn't clear on.  Thanks!

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


import vs imp and friends.

2009-07-23 Thread Emanuele D'Arrigo
Greetings,

I was looking in the archive of this newsgroup and I found this
snippet:

import imp
sourcecode = 'def foo(x): return 11*x'
mod = imp.new_module('foo')
exec sourcecode in mod.__dict__
mod.foo(16)

Together with similar and sometimes more complete snippets available
they show how a module can be created out of string, plain text files
and compiled files. Neat!

Now the question. Apart from checking sys.module first and eventually
adding the new module to it if it isn't there already, and apart from
setting __file__, is there anything else that import does and this
snippet doesn't?

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


Re: ANN: psyco V2

2009-07-23 Thread Neuruss
It seems psyco.org is still in the transfer process...
Is there any charitable soul with a link to a Windows binary? :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import vs imp and friends.

2009-07-23 Thread Christian Heimes
Emanuele D'Arrigo wrote:
 Now the question. Apart from checking sys.module first and eventually
 adding the new module to it if it isn't there already, and apart from
 setting __file__, is there anything else that import does and this
 snippet doesn't?

The import statement does several things. For instance it holds the
import lock to stop other threads from importing the same module again.
It also does lots of additional work for packages like relative imports,
checking __path__, setting attributes on parent packages and so on. The
import system also does a lot of work in order to find and load a
module, too.

Christian



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


Re: Detect target name in descriptor __set__ method

2009-07-23 Thread Rainer Mansfeld

Gabriel Genellina schrieb:
I have a class attribute 'foo' which is a data descriptor. I create an 
instance of such class. When I say instance.foo = value, the descriptor 
__set__ method is called. Is there any way to obtain the name being 
assigned to? ('foo' in this example). That is, I want to know the target 
name for the assignment that triggered the __set__ method call.




class descriptor(object):
def __get__(self, instance, owner):
  return self

def __set__(self, instance, value):
# I want to know the *name* this value is being assigned to
for name in instance.__class__.__dict__:
if getattr(instance, name) is self:
print assigning to %s % name
break


class X(object):
foo = descriptor()
bar = descriptor()

class Y(object):
foo = descriptor()
baz = descriptor()

x = X()
y = Y()

x.foo = value
x.bar = value
y.foo = value
y.baz = value

Does this work for you?

   Rainer

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


Re: ANN: psyco V2

2009-07-23 Thread Christian Heimes
Neuruss wrote:
 It seems psyco.org is still in the transfer process...
 Is there any charitable soul with a link to a Windows binary? :-)

It seems like Christian is already working on Windows binaries. We are
having a discussing about an obscure MinGW bug on the Python developer
list. It looks like MinGW isn't fully ABI compatible with MSVC.

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


Re: ANN: psyco V2

2009-07-23 Thread Christian Heimes
Christian Tismer wrote:
 Psyco V2 will run on X86 based 32 bit Linux, 32 bit Windows,
 and Mac OS X. Psyco is not supporting 64 bit, yet. But it
 is well being considered.

Can you estimate how much work needs to be done in order to get Psyco
working on 64bit POSIX (Linux) systems?

Christian

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


Re: regex: multiple matching for one string

2009-07-23 Thread Nick Dumas
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Agreed. Two string.split()s, first at the semi-colon and then at the
equal sign, will yield you your value, without having to fool around
with regexes.

On 7/23/2009 9:23 AM, Mark Lawrence wrote:
 scriptlear...@gmail.com wrote:
 For example, I have a string #a=valuea;b=valueb;c=valuec;, and I
 will like to take out the values (valuea, valueb, and valuec).  How do
 I do that in Python?  The group method will only return the matched
 part.  Thanks.

 p = re.compile('#a=*;b=*;c=*;')
 m = p.match(line)
 if m:
  print m.group(),
 
 IMHO a regex for this is overkill, a combination of string methods such
 as split and find should suffice.
 
 Regards.
 
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkpogb0ACgkQLMI5fndAv9jtOwCgj3+YOLfKGvAdyCMOhh4NGgfy
x5YAn1ydhUYxGlvC4Z4WlWKaa1gwviSh
=jnp1
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Office COM automatisation - calling python from VBA

2009-07-23 Thread Dushku, Aaron - Amherst, MA
I'd like a copy of that code.  Thanks for taking the time for all of us.


Sincerely,
Aaron Dushku


**
Aaron Dushku
GIS Specialist
USDA-NRCS
Amherst, Massachusetts
(413) 253-4379
Email:  aaron.dushku at ma.usda.gov


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


win32clipboard operation

2009-07-23 Thread LeeRisq
Hi all,

Newbie question. I've written a script that outputs to a text file.

Now, I just want to copy the content to win32clipboard for access to
other applications. Here's the mess I've come up with so far:)

import xlrd
import win32clipboard



def program_uno():
ofile = open(rC:\Query\DQL.txt, w)
book = xlrd.open_workbook(C:\DocLoader\MCL_Drawing and Legacy
Docloader Sheet.xls)
sh = book.sheet_by_index(0)
e = sh.cell_value(1, 0)
a = sh.col_values(0, start_rowx=2, end_rowx=200)
b = r'%' + e
c = r'%Draft%'
y = rsome text... %(b, c)
w = rsome more text...
ofile.writelines(y)
for x in a:
d = r'%' + x
z = r loop text... %(d, c)
f = ofile.writelines(z)
ofile.writelines(w)


def copy_text():
ifile = open(rC:\Query\DQL.txt, r)


win32clipboard.OpenClipboard(0)
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText()
win32clipboard.CloseClipboard

program_uno()
copy_text()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is file.encoding convention?

2009-07-23 Thread Vinay Sajip
On Jul 23, 4:06 am, Naoki INADA songofaca...@gmail.com wrote:
 In document http://docs.python.org/library/
 stdtypes.html#file.encoding:

  The encoding that this file uses. When Unicode strings are written to a 
  file,
   they will be converted to byte strings using this encoding. In addition,
  when the file is connected to a terminal, the attribute gives the encoding
  that the terminal is likely to use

 But inlogging.StreamHandler.emit() ::

 try:
 if (isinstance(msg, unicode) and
 getattr(stream, 'encoding', None)):
 #fs = fs.decode(stream.encoding)
 try:
 stream.write(fs % msg)
 except UnicodeEncodeError:
 #Printing to terminals sometimes fails.
 For example,
 #with an encoding of 'cp1251', the above
 write will
 #work if written to a stream opened or
 wrapped by
 #the codecs module, but fail when writing
 to a
 #terminal even when the codepage is set to
 cp1251.
 #An extra encoding step seems to be
 needed.
 stream.write((fs % msg).encode
 (stream.encoding))
 else:
 stream.write(fs % msg)
 except UnicodeError:
 stream.write(fs % msg.encode(UTF-8))

 And behavior of sys.stdout in Windows:: import sys
  sys.stdout.encoding
 'cp932'
  u = uあいう
  u

 u'\u3042\u3044\u3046' print sys.stdout, u
 あいう
  sys.stderr.write(u)

 Traceback (most recent call last):
   File stdin, line 1, in module
 UnicodeEncodeError: 'ascii' codec can't encode characters in position
 0-2: ordinal not in range(128)

 What is file.encoding convention?
 If I want to write a unicode string to a file(-like) that have
 encoding attribute, I should do
 (1) try: file.write(unicode_str),
 (2) except UnicodeEncodeError: file.write(unicode_str.encode
 (file.encoding))
 likelogging?
 It seems agly.

If you are writing a Unicode string to a stream which has been opened
with e.g. codecs.open with a specific encoding, then the stream is
actually a wrapper. You can write Unicode strings directly to it, and
the wrapper stream will encode the Unicode to bytes using the specific
encoding and write those bytes to the underlyting stream. In your
example you didn't show sys.stderr.encoding - you showed
sys.stdout.encoding and printed out something to it which seemed to
give the correct result, but then wrote to sys.stderr which gave a
UnicodeEncodeError. What is the encoding of sys.stderr in your
example? Also note that logging had to handle what appeared to be an
oddity with terminals - they (at least sometimes) have an encoding
attribute but appear to expect to have bytes written to them, and not
Unicode. Hence the logging kludge, which should not be needed and so
has been carefully commented.

Regards,

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


Re: regex: multiple matching for one string

2009-07-23 Thread Bill Davy
Mark Lawrence breamore...@yahoo.co.uk wrote in message 
news:mailman.3588.1248355389.8015.python-l...@python.org...
 scriptlear...@gmail.com wrote:
 For example, I have a string #a=valuea;b=valueb;c=valuec;, and I
 will like to take out the values (valuea, valueb, and valuec).  How do
 I do that in Python?  The group method will only return the matched
 part.  Thanks.

 p = re.compile('#a=*;b=*;c=*;')
 m = p.match(line)
 if m:
  print m.group(),

 IMHO a regex for this is overkill, a combination of string methods such as 
 split and find should suffice.

 Regards.



For the OP, it can be done with regex by grouping:

p = re.compile(r'#a=(*);b=(*);c=(*);')
m = p.match(line)
   if m:
 print m.group(1),

m.group(1) has valuea in it, etc.

But this may not be the best way, but it is reasonably terse. 


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


extract c/cpp include file with regular expression

2009-07-23 Thread tiefeng wu
Hi all!
I need to parse c/cpp source files, one requirement is to extract
included header file name.
here is my solution:
 p = re.compile(r'#\s*include\s+(?:()|())(.*)(?(1))(?(2))')
 m = re.search(p, '#include header.h')
 m.group(3)
'header.h'
 m = re.search(p, '#include header.h')
 m.group(3)
'header.h'
 m = re.search(p, '#include header.h')
 print(m)
None
 m = re.search(p, '#include header.h')
 print(m)
None

Pretty ugly! And I know for a valid c/cpp source file, it will be not
necessary to check and match '' with '' and  with ,
but I'm wondering to see more elegant way to do such thing.

tiefeng wu
2009-07-23
-- 
http://mail.python.org/mailman/listinfo/python-list


Cannot Get Form To Work

2009-07-23 Thread Victor Subervi
Hi:
When the form comes up the first time, there is the default value for num.
When I fill in a number in the form and press send, even though the form
sends to itself (same page name), I would think it would read the number
sent. Here again is the code:

from primeNumbers import primeNumbers

try:
 lang = form.getfirst('lang', 'en')
 browser = form.getfirst('browser', 'all')
 site = form.getfirst('site', 'bridge')
 num = form.getfirst('num','')
except:
 pass

ourFile = string.split(__file__, /)
p = ourFile[len(ourFile) - 1]
p = p[: - 9]
site = ourFile[4][:-10]
if site != '':
 site = site[:-1]

print Content-Type: text/html
print
print 
!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Frameset//EN 
http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd;
head xmlns=http://www.w3.org/1999/xhtml;
/head

if num != '':
 num = round(float(num))
 roots = primeNumbers(num)
 print roots
if num == '':
 print 
form action=http://13gems.com/test-Calculators_frame.py; method=post
input type=text name=num size=20 maxlength=20 value=Enter number
here... onfocus=this.value='' /
input type=image src=http://13gems.com/images/search.jpg; name=search
id=search /
/form

print '/body/html\n'
-- 
http://mail.python.org/mailman/listinfo/python-list


strange python scripting error

2009-07-23 Thread Mark Tarver
I have a very strange error.  I have two test python files test.py and
python.py which contain the following code

#!/usr/bin/python
print Content-type: text/html
print
print html
print centerHello, Linux.com!/center
print /html

One file (test.py) works; you call it up and it shows a web page with

Hello, Linux.com

The other fails with a server configuration error.  Both are running
under Linux, same server, same permissions.  Running a character scan
shows that both files contain the same printable characters and are
therefore typographically identical.   They are absolutely the same.

The only hint at a difference I can see is that my ftp program says
the files are of unequal lengths.  test.py is 129 bytes long.
python.py 134 bytes long.

A zipped folder containing both files is at

www.lambdassociates.org/weird.zip

Any ideas welcome.

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


Re: regex: multiple matching for one string

2009-07-23 Thread tiefeng wu
2009/7/23 scriptlear...@gmail.com scriptlear...@gmail.com:
 For example, I have a string #a=valuea;b=valueb;c=valuec;, and I
 will like to take out the values (valuea, valueb, and valuec).  How do
 I do that in Python?  The group method will only return the matched
 part.  Thanks.

 p = re.compile('#a=*;b=*;c=*;')
 m = p.match(line)
        if m:
             print m.group(),
 --
 http://mail.python.org/mailman/listinfo/python-list


maybe like this:
 p = re.compile(r'#?\w+=(\w+);')
 l = re.findall(p, '#a=valuea;b=valueb;c=valuec;')
 for r in l: print(r)
...
valuea
valueb
valuec

tiefeng wu
2009-07-23
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: extract c/cpp include file with regular expression

2009-07-23 Thread Philip Semanchuk


On Jul 23, 2009, at 11:46 AM, tiefeng wu wrote:


Hi all!
I need to parse c/cpp source files, one requirement is to extract
included header file name.
here is my solution:

p = re.compile(r'#\s*include\s+(?:()|())(.*)(?(1))(?(2))')
m = re.search(p, '#include header.h')
m.group(3)

'header.h'

m = re.search(p, '#include header.h')
m.group(3)

'header.h'

m = re.search(p, '#include header.h')
print(m)

None

m = re.search(p, '#include header.h')
print(m)

None

Pretty ugly! And I know for a valid c/cpp source file, it will be not
necessary to check and match '' with '' and  with ,
but I'm wondering to see more elegant way to do such thing.


Hi tiefeng,
Regexes are always a little ugly IMO. =)

A side note -- does your parser need to handle /* comments like this  
one*/?  If so, then regular expressions are not going be sufficient.


Good luck
Philip

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


Re: strange python scripting error

2009-07-23 Thread Diez B. Roggisch
Mark Tarver wrote:

 I have a very strange error.  I have two test python files test.py and
 python.py which contain the following code
 
 #!/usr/bin/python
 print Content-type: text/html
 print
 print html
 print centerHello, Linux.com!/center
 print /html
 
 One file (test.py) works; you call it up and it shows a web page with
 
 Hello, Linux.com
 
 The other fails with a server configuration error.  Both are running
 under Linux, same server, same permissions.  Running a character scan
 shows that both files contain the same printable characters and are
 therefore typographically identical.   They are absolutely the same.
 
 The only hint at a difference I can see is that my ftp program says
 the files are of unequal lengths.  test.py is 129 bytes long.
 python.py 134 bytes long.
 
 A zipped folder containing both files is at
 
 www.lambdassociates.org/weird.zip
 
 Any ideas welcome.

They have different line-ending-conventions. Not sure if and why that makes
a difference.

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


Re: win32clipboard operation

2009-07-23 Thread MRAB

LeeRisq wrote:

Hi all,

Newbie question. I've written a script that outputs to a text file.

Now, I just want to copy the content to win32clipboard for access to
other applications. Here's the mess I've come up with so far:)


[snip]

def copy_text():
ifile = open(rC:\Query\DQL.txt, r)
text = ifile.read()
ifile.close()

win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(text)
win32clipboard.CloseClipboard()

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


Re: sqlite3 performance problems only in python

2009-07-23 Thread David Stanek
On Thu, Jul 23, 2009 at 9:02 AM, Stef Mientkistef.mien...@gmail.com wrote:

 btw, I don't know if it's of any importance, the SQL-statement I perform is
 select OPNAMEN.*, NAME, NAME_, SCORES.SCORE, PATIENT.*
  from OPNAMEN
   inner join POID_VLID          on OPNAMEN.POID            = POID_VLID.POID
   inner join VRAAGLST           on VRAAGLST.VLID           = POID_VLID.VLID
   inner join VLID_SSID          on VRAAGLST.VLID           = VLID_SSID.VLID
   inner join SUBSCHAAL_GEGEVENS on SUBSCHAAL_GEGEVENS.SSID = VLID_SSID.SSID
   inner join POID_SSID_SCID     on ( OPNAMEN.POID            =
 POID_SSID_SCID.POID ) and
                                    ( SUBSCHAAL_GEGEVENS.SSID =
 POID_SSID_SCID.SSID )
   inner join SCORES             on SCORES.SCID             =
 POID_SSID_SCID.SCID
   inner join PID_POID           on OPNAMEN.POID            = PID_POID.POID
   inner join PATIENT            on PATIENT.PID             = PID_POID.PID
  where substr ( lower( NAME) , 1, 6)  = 'cis20r'
   and lower ( NAME_ ) = 'fatigue'
   and TEST_COUNT in (3,4)
   and DATETIME  39814.0
   and SCORE  30

Warning: I suck at SQL and hate it with a passion...

By using lower() on the left side of the where expressions I believe
that you are table scanning. So it is not the size of the data
returned, but the size of the data that needs to be scanned.

-- 
David
blog: http://www.traceback.org
twitter: http://twitter.com/dstanek
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: extract c/cpp include file with regular expression

2009-07-23 Thread MRAB

tiefeng wu wrote:

Hi all!
I need to parse c/cpp source files, one requirement is to extract
included header file name.
here is my solution:

p = re.compile(r'#\s*include\s+(?:()|())(.*)(?(1))(?(2))')
m = re.search(p, '#include header.h')
m.group(3)

'header.h'

m = re.search(p, '#include header.h')
m.group(3)

'header.h'

m = re.search(p, '#include header.h')
print(m)

None

m = re.search(p, '#include header.h')
print(m)

None

Pretty ugly! And I know for a valid c/cpp source file, it will be not
necessary to check and match '' with '' and  with ,
but I'm wondering to see more elegant way to do such thing.


I'd probably do:

 p = re.compile(r'#\s*include\s+(?:([^]*)|([^]*))')
 m = p.search('#include header.h')
 m.group(1) or m.group(2)
'header.h'
--
http://mail.python.org/mailman/listinfo/python-list


Re: strange python scripting error

2009-07-23 Thread Richard Brodie

Diez B. Roggisch de...@nospam.web.de wrote in message 
news:7crfjof29e4g...@mid.uni-berlin.de...

 They have different line-ending-conventions. Not sure if and why that makes
 a difference.

Depends on your setup. Shells can be a bit dumb about it, so
it will likely break simple cgi-style hosting.

-bash: ./python.py: /usr/bin/python^M: bad interpreter: 


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


Re: strange python scripting error

2009-07-23 Thread Peter Otten
Diez B. Roggisch wrote:

 Mark Tarver wrote:
 
 I have a very strange error.  I have two test python files test.py and
 python.py which contain the following code
 
 #!/usr/bin/python
 print Content-type: text/html
 print
 print html
 print centerHello, Linux.com!/center
 print /html
 
 One file (test.py) works; you call it up and it shows a web page with
 
 Hello, Linux.com
 
 The other fails with a server configuration error.  Both are running
 under Linux, same server, same permissions.  Running a character scan
 shows that both files contain the same printable characters and are
 therefore typographically identical.   They are absolutely the same.
 
 The only hint at a difference I can see is that my ftp program says
 the files are of unequal lengths.  test.py is 129 bytes long.
 python.py 134 bytes long.
 
 A zipped folder containing both files is at
 
 www.lambdassociates.org/weird.zip
 
 Any ideas welcome.
 
 They have different line-ending-conventions. Not sure if and why that
 makes a difference.

Looks like the shell treats the CR as part of the interpreter name:

$ cat python.py
#!/usr/bin/python
print Content-type: text/html
print
print html
print centerHello, Linux.com!/center
print /html$
$ python python.py
Content-type: text/html

html
centerHello, Linux.com!/center
/html
$ chmod u+x python.py
$ ./python.py
bash: ./python.py: /usr/bin/python^M: bad interpreter: No such file or 
directory

Peter

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


Re: extract c/cpp include file with regular expression

2009-07-23 Thread tiefeng wu
MRAB wrote:
 I'd probably do:

 p = re.compile(r'#\s*include\s+(?:([^]*)|([^]*))')
 m = p.search('#include header.h')
 m.group(1) or m.group(2)
 'header.h'


yes, it's easier to understand.
thanks, MRAB!
I always make things complicated :P

tiefeng wu
2009-07-23
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Detect target name in descriptor __set__ method

2009-07-23 Thread DG
On Jul 23, 8:44 am, Rainer Mansfeld mli...@romulo.de wrote:
 Gabriel Genellina schrieb:

  I have a class attribute 'foo' which is a data descriptor. I create an
  instance of such class. When I say instance.foo = value, the descriptor
  __set__ method is called. Is there any way to obtain the name being
  assigned to? ('foo' in this example). That is, I want to know the target
  name for the assignment that triggered the __set__ method call.

 class descriptor(object):
      def __get__(self, instance, owner):
        return self

      def __set__(self, instance, value):
          # I want to know the *name* this value is being assigned to
          for name in instance.__class__.__dict__:
              if getattr(instance, name) is self:
                  print assigning to %s % name
                  break

 class X(object):
      foo = descriptor()
      bar = descriptor()

 class Y(object):
      foo = descriptor()
      baz = descriptor()

 x = X()
 y = Y()

 x.foo = value
 x.bar = value
 y.foo = value
 y.baz = value

 Does this work for you?

     Rainer

The reason I wasn't checking the class' '__dict__' attribute in my
solution was because this won't show any descriptors that were
inherited from base classes.  Example with some optimizations below
(sorry for the long code):

builtin_methods = dir(object)

class descriptor(object):
def __init__(self):
self.name = None

def __get__(self, instance, owner):
# if you want a 'useful' data descriptor only return self upon
# non-instance access
if instance is None:
return self
else:
# do something besides the below for the usefulness
return self

def __set__(self, instance, value):
if self.name is None:
cls = instance.__class__
dir_attrs = [m for m in dir(cls) if m not in
builtin_methods]
# 'foo' is printed here
print 'dir(cls):', dir_attrs
# 'foo' is not printed here
print 'cls.__dict__:', cls.__dict__
for name in dir_attrs:
if getattr(cls, name) is self:
self.name = name
print setting %s to %s % (self.name, value)


class baseX(object):
foo = descriptor()

class X(baseX):
pass

x = X()
x.foo = 'bar'

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


Re: extract c/cpp include file with regular expression

2009-07-23 Thread tiefeng wu
2009/7/24 Philip Semanchuk phi...@semanchuk.com:

 I know this will sound like a sarcastic comment, but it is sincere: my
 suggestion is that if you want to parse C/C++ (or Python, or Perl, or
 Fortran, etc.), use a real parser, not regexes unless you're willing to
 sacrifice some accuracy. Sooner or later you'll come across some code that
 your regexes won't handle, like this --

 #ifdef FOO_BAR
 #include this.h
 /* #else */
 #include that.h
 #endif


 Parsing code is difficult...

I understand your point, thanks for your suggestion, Philip. And I've
met the problem like in your example
The reason I choose regex because I barely know about real parser,
for me it still in some dark area :)
But I'll find something to learn.

tiefeng wu
2009-07-23
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: psyco V2

2009-07-23 Thread Christian Tismer

On 7/23/09 8:22 AM, Christian Heimes wrote:

Christian Tismer wrote:

Psyco V2 will run on X86 based 32 bit Linux, 32 bit Windows,
and Mac OS X. Psyco is not supporting 64 bit, yet. But it
is well being considered.


Can you estimate how much work needs to be done in order to get Psyco
working on 64bit POSIX (Linux) systems?


This is not easy to tell. I'm in the process of estimating
this, because my sponsor wants to know as well. They are
very interested, but it has to be somehow affordable in
time and money.

There are different paths that can be taken. Simply hacking away,
trying to go straight to 64 bit is obvious, but probably a bad
approach. Half of the system needs to be rewritten and augmented
with extra size info, and this goes very deep. I think this
way I would produce a nightmare of even more complicated code,
and would kill myself debugging-wise.

I believe I need to simplify psyco and make many parts more
abstract and more general, to become able to make it flexible.
This also means slowing the compiler down quite a lot.

Slowing it down will again become no problem, when my new
compiler strategy is ready. The number of compilations
will reduce so drastically, that the slowdown is neglectible.

Yes, I did not give an answer. I have the vague feeling of
three months full-time work. My problem right now is to
ensure that it will become less and not more :-)

cheers - chris
--
Christian Tismer :^)   mailto:tis...@stackless.com
tismerysoft GmbH : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9A :*Starship* http://starship.python.net/
14109 Berlin : PGP key - http://wwwkeys.pgp.net/
work +49 30 802 86 56  mobile +49 173 24 18 776  fax +49 30 80 90 57 05
PGP 0x57F3BF04   9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
  whom do you want to sponsor today?   http://www.stackless.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Changing the private variables content

2009-07-23 Thread Ethan Furman
Or, in other words, what Steven D'Aprano had already said.  Guess I 
should read the whole thread before madly posting!  :)


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


Re: Balanced binary tree implementation

2009-07-23 Thread M.-A. Lemburg
Lucas P Melo wrote:
 Hello,
 
 I would like to use a balanced binary tree implementation (preferably
 within some API).
 Any hints about where I could find it?
 
 I am looking for something that implements insertion, deletion, search
 and a special search that returns the lesser element bigger than a given
 key [1].
 
 A nice possibility would be an extensible API that allows me to inherit
 its classes and to add operations myself.
 
 Thanks in advance.
 
 [1] Ex: 1 2 3 4 5 6 are elements of the bbt. If I use this operation
 given 4 as the parameter, the value returned would be 5.

You might want to have a look at the btree implementation we
have in mxBeeBase:

http://www.egenix.com/products/python/mxBase/mxBeeBase/

It's written in C and optimized for on-disk operations.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jul 23 2009)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: extract c/cpp include file with regular expression

2009-07-23 Thread Philip Semanchuk


On Jul 23, 2009, at 12:36 PM, tiefeng wu wrote:


2009/7/24 Philip Semanchuk phi...@semanchuk.com:


I know this will sound like a sarcastic comment, but it is sincere:  
my

suggestion is that if you want to parse C/C++ (or Python, or Perl, or
Fortran, etc.), use a real parser, not regexes unless you're  
willing to
sacrifice some accuracy. Sooner or later you'll come across some  
code that

your regexes won't handle, like this --

#ifdef FOO_BAR
#include this.h
/* #else */
#include that.h
#endif


Parsing code is difficult...


I understand your point, thanks for your suggestion, Philip. And I've
met the problem like in your example
The reason I choose regex because I barely know about real parser,
for me it still in some dark area :)
But I'll find something to learn.


Yes! Learning is always good. And as I said, if you don't mind missing  
some unusual cases, regexes are fine. I don't know how accurate you  
want your results to be.


As for real parsers, there's lots of them out there, although they may  
be overkill for what you want to do. Here's one written entirely in  
Python:

http://www.dabeaz.com/ply/

Whatever you choose, good luck with it.

Cheers
Philip

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


Re: PyQt GUI

2009-07-23 Thread Robert Kern

On 2009-07-23 03:55, Helvin wrote:

I believe I now have vtkpython.exe. However, my 'import vtk' statement
in my python code is not working. The error says something like no
module named vtk.
Where do I find modules for vtk in pyqt? Do they exist?


There are no VTK modules in PyQt itself. The PyQt support is in the vtk package 
which can be built with VTK itself. You will need to install VTK and the vtk 
package correctly in order to achieve this. vtkpython.exe is not going to help 
you. Ignore it. After you have built VTK, you need to do an extra step to 
install the vtk package to where your Python interpreter will be able to find it.


Let's say that your build directory is c:\vtkbuild.

  cd \vtkbuild\Wrapping\Python
  python setup.py install
  cd \

Now you should be able to import vtk from your normal Python interpreter. If you 
are still having problems, you will need to copy-and-paste exactly what you did 
and what error messages you got. Do not paraphrase error messages.


--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: ANN: psyco V2

2009-07-23 Thread Christian Tismer

On 7/17/09 4:11 AM, Bearophile wrote:

Very good, thank you. I'll try it when I can.

Is Psyco3 going to borrow/steal some ideas/code from Unladen Swallow?


Psyco3: nice typo! :-)

Well, I haven't so far found a new idea there that I'd want
to borrow and did not know from PyPy, before.
Wasn't the project plan saying the opposite, borrowing
some ideas from psyco? :-)
http://code.google.com/p/unladen-swallow/wiki/ProjectPlan


The problem I have with Psyco1.6 is that you can't use the normal
profilers to know how much seconds of running time is taken by each
function/method of your code.


Yes, the profiler hooks are not useful with psyco. You need
to write extra functions for timing, as we do in the benchmark
directory.


Psyco1.6 has a profile() function, but I am not much able to use it
yet.


The profile() function is used for profile driven compilation,
as opposed to psyco.full(). This will go away, pretty soon.
Psyco will only be switched on or off.

Maybe I will add an option for profiling the compiled code.
Interesting idea!

cheers - chris

--
Christian Tismer :^)   mailto:tis...@stackless.com
tismerysoft GmbH : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9A :*Starship* http://starship.python.net/
14109 Berlin : PGP key - http://wwwkeys.pgp.net/
work +49 30 802 86 56  mobile +49 173 24 18 776  fax +49 30 80 90 57 05
PGP 0x57F3BF04   9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
  whom do you want to sponsor today?   http://www.stackless.com/
--
http://mail.python.org/mailman/listinfo/python-list


installing 2.6 on vista64

2009-07-23 Thread DwBear75
I just downloaded and attempted to install python 2.6.2.  The
installer proceeds to do its work then dies, leaving an entry in the
eventlog:

Windows Installer installed the product. Product Name: Python 2.6.2.
Product Version: 2.6.2150. Product Language: 1033. Installation
success or error status: 1602.

Googling for this I wasn't able to narrow the results down to
something usable. Anyone know of issues and how to fix them installing
on vista 64 (yes, I have 8 gigs of ram)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: win32clipboard operation

2009-07-23 Thread LeeRisq
On Jul 23, 9:05 am, MRAB pyt...@mrabarnett.plus.com wrote:
 LeeRisq wrote:
  Hi all,

  Newbie question. I've written a script that outputs to a text file.

  Now, I just want to copy the content to win32clipboard for access to
  other applications. Here's the mess I've come up with so far:)

 [snip]

 def copy_text():
      ifile = open(rC:\Query\DQL.txt, r)
      text = ifile.read()
      ifile.close()

      win32clipboard.OpenClipboard()
      win32clipboard.EmptyClipboard()
      win32clipboard.SetClipboardText(text)
      win32clipboard.CloseClipboard()

I've actually tried this configuration, but I did it again just to be
sure. The program executes without exception, but the text still isn't
copied to the clipboard. Any ideas?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: import vs imp and friends.

2009-07-23 Thread Robert Kern

On 2009-07-23 09:44, Emanuele D'Arrigo wrote:

Greetings,

I was looking in the archive of this newsgroup and I found this
snippet:

import imp
sourcecode = 'def foo(x): return 11*x'
mod = imp.new_module('foo')
exec sourcecode in mod.__dict__
mod.foo(16)

Together with similar and sometimes more complete snippets available
they show how a module can be created out of string, plain text files
and compiled files. Neat!

Now the question. Apart from checking sys.module first and eventually
adding the new module to it if it isn't there already, and apart from
setting __file__, is there anything else that import does and this
snippet doesn't?


Brett Cannon has a good presentation that covers basically the entirety of the 
import mechanism:


http://us.pycon.org/2008/conference/schedule/event/12/

--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: If Scheme is so good why MIT drops it?

2009-07-23 Thread Isaac Gouy
On Jul 21, 10:09 pm, Raffael Cavallaro
raffaelcavall...@pas.espam.s.il.vous.plait.mac.com wrote:
 On 2009-07-21 19:06:02 -0400, Neil Hodgson
 nyamatongwe+thun...@gmail.com said:

     Python uses native threads.

 So it can be teh-slowness on all ur cores!

 http://shootout.alioth.debian.org/u64q/benchmark.php?test=nbody〈=all

 The global interpreter lock doesn't help much either.


As you've linked to programs that /have not/ been written to use
threading or multiple cores (look at the ~ CPU Load column) I get
the feeling I'm missing the joke?



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


Re: Help understanding the decisions *behind* python?

2009-07-23 Thread Mark Lawrence

Phillip B Oldham wrote:

My colleagues and I have been working with python for around 6 months
now, and while we love a lot of what python has done for us and what
it enables us to do some of the decisions behind such certain
data-types and their related methods baffle us slightly (when compared
to the decisions made in other, similarly powerful languages).

Specifically the differences between lists and tuples have us
confused and have caused many discussions in the office. We
understand that lists are mutable and tuples are not, but we're a
little lost as to why the two were kept separate from the start. They
both perform a very similar job as far as we can tell.



[rest of original snipped as already discussed]

Sorry if this has been discussed and I've missed it, but how about 
memory allocation.  An immutable tuple has a fixed memory allocation 
whereas that for the mutable list must be liable to change.  You might 
like to look at the recent thread on this ng 'List insertion cost' and 
follow the links to Raymond Hettinger's power point presentation.


Kindest regards.

Mark Lawrence.

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


Re: challenging problem for changing to a dedicated non-privileged user within a script.

2009-07-23 Thread Piet van Oostrum
 Krishnakant hackin...@gmail.com (K) wrote:

K On Thu, 2009-07-23 at 13:50 +0200, paul wrote:
 If the user running python program is allowed to call setuid() then yes.
 
K NO, i don't think i can do that.  I am getting opperation not permitted.

K Any ways I think probably subprocess will have to sort it out.

 Did you try running sudo -u postgres blabla with subprocess?
 
K Yes, but still not got the intended result which is now obvious.
  2. now execute the python code for connecting to the postgresql
  database.
  In the second point I actually want to execute python code not shell
  level command so will the sudo -u in the subprocess.Popen change the
  user in the script?
 No, as the name subprocess suggests you are spawning a new process 
 which gets another uid through sudo. This does not affect the parent 
 process.
 
K Ok then here is the work-around which I am thinking to try, Plese tell
K me if it is correct.
K I will let that subprocess start python inthe background and execute the
K connecting code to postgresql including importing the pygresql library.
K Then I will create the connection and cursor objcts in that subprocess.
K But my concern is, will the connection object in the child process
K (subprocess) be available to the parrent process?

No. However it is still not clear why you want to run under the postgres
user id. Why can't the original process not do the postgres connection?

If that is really impossible, then you might start the new process with
sudo and let it do a socket tunnelling to postgress, i.e. make a
connection to the postgres server and a socket connection to the
original Python script, and copy everything from one socket to the other
- in both directions. However this can also be done with a ssh tunnel
which might be simpler.
-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: If Scheme is so good why MIT drops it?

2009-07-23 Thread game_designer
Perhaps like Xah Lee I find, after many years of Lisp programming,
these discussions increasingly frustrating and even, in some sense,
amazing. We can speculate all we want about syntax and semantics of
programing languages. What counts in the end are really the PRAGMATICS
of programming languages. How can I do something with a language that
is USEFUL to me? Will the result be good looking, and snappy or some
ugly, dated looking, crashing application? For instance, last time I
played with Scheme (drScheme) to explore some OpenGL 3D issue I was
not impressed at all. One can debate the syntax and semantics of
Scheme but in that particular instance all that was important to me
was the fact that the Scheme example performed terrible and the
threading fell completely apart when running more that a single OpenGL
window. Perhaps this was coded poorly but I don't care. Scheme left a
pretty bad impression.


alex

Prof. Alexander Repenning

University of Colorado
Computer Science Department
Boulder, CO 80309-430
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sqlite3 performance problems only in python

2009-07-23 Thread Piet van Oostrum
 Stef Mientki stef.mien...@gmail.com (SM) wrote:

SM btw, I don't know if it's of any importance, the SQL-statement I perform is
SM select OPNAMEN.*, NAME, NAME_, SCORES.SCORE, PATIENT.*
SM  from OPNAMEN
SMinner join POID_VLID  on OPNAMEN.POID= 
POID_VLID.POID
SMinner join VRAAGLST   on VRAAGLST.VLID   = 
POID_VLID.VLID
SMinner join VLID_SSID  on VRAAGLST.VLID   = 
VLID_SSID.VLID
SMinner join SUBSCHAAL_GEGEVENS on SUBSCHAAL_GEGEVENS.SSID = 
VLID_SSID.SSID
SMinner join POID_SSID_SCID on ( OPNAMEN.POID=
SM POID_SSID_SCID.POID ) and
SM ( SUBSCHAAL_GEGEVENS.SSID =
SM POID_SSID_SCID.SSID )
SMinner join SCORES on SCORES.SCID =
SM POID_SSID_SCID.SCID
SMinner join PID_POID   on OPNAMEN.POID= PID_POID.POID
SMinner join PATIENTon PATIENT.PID = PID_POID.PID
SM  where substr ( lower( NAME) , 1, 6)  = 'cis20r'
SMand lower ( NAME_ ) = 'fatigue'
SMand TEST_COUNT in (3,4)
SMand DATETIME  39814.0
SMand SCORE  30

1) Do you have indices on the join fields?
2) Look at the ANALYZE command
3) Look at the EXPLAIN command
-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >