Re: New to python, open source Mac OS X IDE?

2009-01-28 Thread aspersieman

7stud wrote:

On Jan 27, 6:07 pm, Burukena  wrote:
  

On 1/27/09 8:44 PM, James Stroud wrote:



joseph.a.mar...@gmail.com wrote:
  

Greetings! I've heard enough raving about Python, I'm going to see for
myself what all the praise is for!

I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you

even use an IDE for Python?

Any recommendations on open source Python environments?

Thanks!


Try open komodo. I haven't used it because vim is my IDE, but it looks
pretty good.
  
James

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

Vim and a terminal works for me, specifically with screen.



What does 'with screen' mean?
  

http://www.gnu.org/software/screen/

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

  


--
Vince Noir: Howard... Howard... Howard... Howard... Howard... Howard... 
Howard... Howard... Howard... Howard... Howard... Howard?
Howard Moon: This better be good.
Vince Noir: You know the black bits in bananas, are they tarantulas' eggs?
Howard Moon: Please don't speak to me ever again in your life. 

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


Re: 'pretty print' for built in types

2008-12-09 Thread aspersieman

On Tue, 09 Dec 2008 17:31:41 +0200, Robert Dailey <[EMAIL PROTECTED]> wrote:



Is there a built in way to 'pretty print' a dict, list, and tuple
(Amongst other types)? Dicts probably print the ugliest of them all,
and it would be nice to see a way to print them in a readable way. I
can come up with my own function to do this, but I don't want to do
this if I don't have to.


For lists use 'join'. 


lista = ['a', 'b', 'c', 4]
','.join(lista)
a,b,c,4


For more info google 'python join' or see [1]

Regards

Nicol

[1] http://docs.python.org/library/stdtypes.html#string-methods

--

Christopher Columbus was, after all, a super intelligent hypersquirrel from the 
planet Klepton. How else could he have known where to find america?
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to send body and attachements in an email message?

2008-12-03 Thread Aspersieman


On Wed, 03 Dec 2008 12:40:30 +0200, srinivasan srinivas  
<[EMAIL PROTECTED]> wrote:



HI,
I would like to send an email message with body-content 'test' and an  
attachment.

The snippet i used is:
outer = email.mime.multipart.MIMEMultipart()
msg1 = email.mime.text.MIMEText(, _subtype = 'text')
msg1.add_header('Content-Disposition', 'attachment')
outer.attach(msg1)

body = email.mime.text.MIMEText(, _subtype = 'text')
outer.attach(body)

smtp_client = smtplib.SMTP()
smtp_client.connect()
smtp_client.sendmail(, , outer.as_string())
smtp_client.close()

If i do like above, i am receiving the body also as an attachment. How  
to set body to Multipart email message?


Thanks,
Srini


  Add more friends to your messenger and enjoy! Go to  
http://messenger.yahoo.com/invite/

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


Hi there

I have used this method for a while. Works pretty good. (Apologies if the  
formatting is a bit wonky - gmail reformats my stuff)


import mimetypes
import poplib
import email
import smtplib
import os
from email import *
from email.mime import *

def SendMail(self, send_from, send_to, subject, text, files=[],  
server="localhost", username = None, password = None):

# {{{
"""
Sends an email. With optional attachment files.
"""
assert type(send_to)==list
assert type(files)==list

msg = MIMEMultipart.MIMEMultipart()
msg['From'] = send_from
msg['To'] = Utils.COMMASPACE.join(send_to)
msg['Date'] = Utils.formatdate(localtime=True)
msg['Subject'] = subject

msg.attach(MIMEText.MIMEText(text))

for f in files:
part = MIMEBase.MIMEBase("application", "octet-stream")
part.set_payload(open(f,"rb").read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"'  
% os.path.basename(f))

msg.attach(part)

smtp = smtplib.SMTP(server, 25)
smtp.sock.settimeout(120)
try:
if username and password:
smtp.login(username, password)
smtp.sendmail(send_from, send_to, msg.as_string())
else:
smtp.sendmail(send_from, send_to, msg.as_string())
except Exception, err:
print "Error sending to " + str(send_to) + " ERROR : " + str(err)
if self.logger:
self.logger.error("Email error - error sending message to : "  
+ str(send_to) + " Error : " + str(err))


smtp.close()
# }}}

HTH

Nicol
--
Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo
--
http://mail.python.org/mailman/listinfo/python-list


Re: damn street venders

2008-11-05 Thread Aspersieman

+1

--
Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo

On Mon, 03 Nov 2008 16:05:13 +0200, r <[EMAIL PROTECTED]> wrote:


Hey, go sell your stupid watch somewhere else.
i am tired of the message boards clogged with these stupid ads.
Nobody here cares about your cheap rolex watches or porn or anything
else.
This is python, and that is all we care about.
If we want those things we *know* how to find them.
good day!


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



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


Re: Django or TurboGears or Pylons? for python web framework.

2008-11-05 Thread Aspersieman
On Wed, 05 Nov 2008 08:35:23 +0200, 3000 billg <[EMAIL PROTECTED]>  
wrote:



Hi Senior,


Hi

There was a case for web site that will be public to Internet for me. I  
like

python so I do not consider the use of Ruby on Rails.


Excellent choice :)

I searched more web framework of python from Google. The good solution  
just

only there are Django, TurboGears and Pylons.


I would recommend web2py [1].

Just from my preferences, I want to use Django but the AJAX support will  
be
a problem. Also I need to select a JavaScript framework and lean it,  
maybe

JQuery, mootools or other. And I can not write python as it is written in
general javascript. I need to learn a different syntax.


It supports (and comes with) jquery, has awesome ajax integration.


TurboGears or Pylons, I am worried that the issue of performance because
CherryPy.


I have read (somewhere - I can't find the link now, you can probably  
google it) that it runs as fast or faster than django (and some other  
frameworks).



Could everybody give me a hand for your select? Django or Turbegears or
Pylons? and Why?


For Django VS web2py see [2]
For Turbogears VS web2py see [3]


If Django, how to do Ajax support for you? and why?


For info on web2py and ajax see [4].

Also web2py supports SQLite, MySQL, PostgreSQL, MSSQL, FireBird and Oracle  
databases - which is very cool for me as I often need to work on different  
RDBMS's. Internationalisation is also a cinch. Plus - you can run the  
whole framework from a USB drive and it includes a administrative  
interface with a text editor so you can code your project *entirely* in a  
web browser. It also runs on almost anything that supports python :  
windows, unix/linux, OS X etc. I also has a very active and helpful  
mailing list


I have tried a couple of other frameworks but only web2py gave me that  
'just right' feel. Don't, however take only my word for it - and try other  
frameworks to find the one that works for you. One is, fortunately, spoilt  
for choice with all the cool python frameworks these days. :)



thanks eveybody first.


HTH

Nicol

[1] http://www.web2py.com/
[2] http://mdp.cti.depaul.edu/AlterEgo/default/show/101
[3] http://mdp.cti.depaul.edu/AlterEgo/default/show/102
[4] http://mdp.cti.depaul.edu/AlterEgo/default/show/80

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


pymssql stored procedures - NEW THREAD

2008-10-21 Thread Aspersieman
On Tue, 21 Oct 2008 20:44:24 +0200, Mike Hansen <[EMAIL PROTECTED]>  
wrote:



Hi,

I saw your posting on the python list about pymssql and you mentioned  
that you call stored procedures and get back output parameters. Are you  
doing this on Windows or Linux? I can't seem to get it to work on Linux.  
Have you gotten it to work on Linux?


See this discussion on stackoverflow:

http://stackoverflow.com/questions/191644/how-do-you-get-output-parameters-from-a-stored-procedure-in-python

Thanks






Hi there

I hope you don't mind - I made this a new thread on the list, so others  
can maybe help out.


Although I use Linux quite often, I'm afraid MS SQL (with python) from  
Linux is something I have not tried yet. :-/


However - here are some things you might try:
	1) On the pymssql site (http://pymssql.sourceforge.net/#platforms) there  
is some documentation on using MS SQL (specifically with pymssql) from  
Linux - you need to use FreeTDS (http://www.freetds.org/) [although you  
probably know this already so... :)]
	2) (The following I have *only* tried on windows xp and server 2003 and  
SQL Server 2000)
	   I have tried various suggested ways to have pymssql (and indeed a  
couple of other python db libraries - which didn't work) - from extensive  
googling etc., return an output parameter for MS SQL server. The only  
method that works, for me at least, is the following - using pymssql:	
		* Assume stored procedure called : "sp_GetUserID" that has an output  
parameter declared as "@id".
		* Instead of using the "callproc" method of a cursor instead I execute  
the stored procedure as a normal sql statement that would return rows.

import pymssql
con = pymssql.connect   (host='x',user='',
password='x',database='x')
cur = con.cursor()
query = "DECLARE @id INT; EXECUTE sp_GetUserID; SELECT @id;"
cur.execute(query)
outputparameter = cur.fetchall()
con.commit()
con.close()

		* You should now be able to access the output parameter from the list  
object "outputparameter".


HTH

Regards

Nicol

Let me know if thats a bit unclear - it's a bit late here :-p


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


Re: pymssql - execute loads all results into memory!

2008-10-21 Thread Aspersieman
On Tue, 21 Oct 2008 13:06:37 +0200, Tim Golden <[EMAIL PROTECTED]>  
wrote:



Aspersieman wrote:
However, pyODBC doesn't support return variables(parameters) in stored  
procedures (at least with MS SQL). pymssql is the only db api for  
python that I've found that can reliably do this. I've tried adodbapi,  
pyodbc and one or two others (can't think of the names now... :-/).


That's a fair point (I'm assuming you're right; I've never tried). That
tends to be a shortcoming of SQL interfaces. However, pymssql is based
on the defunct ntwdblib.dll interface which is becoming harder and harder
to find as of SQL2005. Have you tried putting a feature request in to
the pyodbc team? I've not had anything to do with them for a bit, but
they did implement the .nextset method at my request a couple of years
ago. (That's assuming it's even possible with ODBC in general, which
I also haven't checked).

TJG
--



Oh, trust me - I've tried a *LOT*. I aggree, submitting a feature request  
is a good idea. I think I'll do that. :)


I did read somewhere (I think on the pyodbc site) that pyodbc isn't DB API  
2.0 feature complete yet - so I'll have to probably check if they haven't  
already planned this.


Obtaining output parameters from stored procedures is something I have to  
do quite often, unfortunately - so maybe I can submit a patch even... :)


Alternatively - I have found the adodbapi quite useful (although it also  
doesn't support output parameters), so I might ask them too.


Thanks for the suggestion.

Regards

Nicol

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


Re: pymssql - execute loads all results into memory!

2008-10-21 Thread Aspersieman

On Tue, 21 Oct 2008 10:14:56 +0200, ChaosKCW <[EMAIL PROTECTED]> wrote:


On Oct 20, 3:38 pm, Tim Golden <[EMAIL PROTECTED]> wrote:

Eric Wertman wrote:
>> I am trying to use pymssql, and have an issue where by the execute
>> (not the fetch) is appearing to load all records into memory.

>> if I execute

>> con = pymssql.connect(...)
>> cur = con.cursor()
>> cur.execute(sql)
>> rec  = cur.fetchone()

>> if I put in a query which returns a lot of records into "sql" then  
the

>> execute never returns, pythons memory usage slowly ballons till the
>> machine cant give anymore. If I put a sql query returning only few
>> rows, then it works fine.

>> So I am not sure why an execute would feel the need to load all rows,
>> but its seriously crippling. Does anyone know if this is a bug or
>> something I can "turn off"

> I ran into this myself.  After some digging I discovered that what you
> are after is a server-side cursor that isn't implemented yet in
> pymssql.  There is one in MySQLdb, but it's not the default behavior.
> Regardless of your usage (fetchone vs fetchmany), the result set is
> held client side.  AFAIK the only workaround is to keep your result
> set small (enough).  If you use fetchmany and iterate over it
> directly, it may keep your memory usage down,  I can't remember if
> that worked.  I definitely tried making a generator with it, that did
> not help.

... or just switch to pyodbc, for example, which behaves
perfectly well with this snippet against a table of >24 million
rows:


import pyodbc

conn = [
  "Driver={SQL Server}",
  "Server=SVR17",
  "Database=TDI",
  "TrustedConnection=Yes"
]
db = pyodbc.connect (";".join (conn))
q = db.cursor ()
q.execute ("SELECT * FROM revenue") # 24 million rows
q.fetchone ()
q.close ()



TJG


Thanks for the responses, I am astounded any db api tool doesnt
support cursors! pymssql is mostly useless, I will switch to an odbc
interface.
--
http://mail.python.org/mailman/listinfo/python-list


Yes this is true, unfortunately...

However, pyODBC doesn't support return variables(parameters) in stored  
procedures (at least with MS SQL). pymssql is the only db api for python  
that I've found that can reliably do this. I've tried adodbapi, pyodbc and  
one or two others (can't think of the names now... :-/).


Regards

Nicol

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


Re: Porn Addiction Solutions?

2008-10-10 Thread Aspersieman

On Fri, 10 Oct 2008 16:11:07 +0200, <[EMAIL PROTECTED]> wrote:


On Oct 10, 7:03 am, Um Jammer NATTY <[EMAIL PROTECTED]> wrote:

On Oct 10, 5:37 am, [EMAIL PROTECTED] wrote:

> It's very simple. You need to know the world is much more than the
> imaginery life you are looking. Spend some time in the feet of the
> Lord Jesus who would help you to come out of this trouble.

Does anyone else find it amusing that this poster assumes 'imaginary'
and the Lord Jesus are polar opposites???


I'm guessing...only you!
--
http://mail.python.org/mailman/listinfo/python-list


Nope, not only him.

On another note, why is this a discussion on c.l.p? Shouldn't we
discourage these kinds of posts?

Nicol

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


Re: win32service and Python

2008-08-13 Thread Aspersieman
David wrote:
> I am collecting informations about win32 services for Python but, except for
> few basic examples about Mark Hammond's win32serviceutil, I found nothing
> useful.
>
> Any link is welcome.
>
> Thank you.
> David
>
>   
This might also be useful:
http://support.microsoft.com/kb/137890

It's doesn't register the service using python - but it's generic enough
to work.

HTH

Nicolaas

-- 

The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle. 


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


Re: Decoding an attachment

2008-08-01 Thread Aspersieman
[EMAIL PROTECTED] wrote:
> I figured out how to save an e-mail message as a text file, but I'm
> not sure how to decode the encoded part as I am not sure how much I
> need to include to decode it properly.  Here is what a message looks
> like:
>
>
> Received: from INGESTOR2SQA ([10.220.83.198]) by sqaserver300 with
> Microsoft SMTPSVC(6.0.3790.0);
>Thu, 31 Jul 2008 12:10:26 -0700
> mime-version: 1.0
> from: "AVDN Ingestor" <[EMAIL PROTECTED]>
> to: [EMAIL PROTECTED]
> date: 31 Jul 2008 17:53:40 +
> subject: Upload Status for test
> content-type: multipart/mixed; boundary=--boundary_2_09ab8836-
> ff06-41a6-94d6-59258539bf88
> Return-Path: [EMAIL PROTECTED]
> Message-ID: <[EMAIL PROTECTED]>
> X-OriginalArrivalTime: 31 Jul 2008 19:10:26.0125 (UTC)
> FILETIME=[16D08FD0:01C8F341]
>
>
> boundary_2_09ab8836-ff06-41a6-94d6-59258539bf88
> content-type: text/plain; charset=us-ascii
> content-transfer-encoding: quoted-printable
>
> For additional information, please see attachment.
> boundary_2_09ab8836-ff06-41a6-94d6-59258539bf88
> content-type: text/xml; name=status.xml; charset=utf-8
> content-transfer-encoding: base64
> content-disposition: attachment
>
> PGF2ZG5fcG5tIHZlcnNpb249IjEuMSIgc2VuZGVyPSJhdmRud2VzdGRjMSIgZG9j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YxZTNk
> NmViY2Y3MDQ3MDVhYyIgZmlsZW5hbWU9Ilx2aWRlb1xmb29cYm91Z2UwMDMuMzIwXzI0MF9u
> dHNjX2FjMy50cyIgbm90aWZpY2F0aW9uPSIxMjAiIC8+PC9hdmRuX3BubT4=
> boundary_2_09ab8836-ff06-41a6-94d6-59258539bf88--
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>   
You need to get the content type ('content-type: text/xml;' from email
headers above) using the email library method 'get_content_type'. Then
get filename using the get_filename method. This will help you decide
what to do with the attachment and how to save it (see [1] for help on
email library). Then use base64 library to decode the attachment (see [2])
 
[1] http://docs.python.org/lib/module-email.html
[2] http://www.python.org/doc/2.3/lib/module-base64.html

HTH

Regards

Nicolaas

-- 

The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle. 


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


Re: saving an e-mail attachement

2008-08-01 Thread Aspersieman
[EMAIL PROTECTED] wrote:
> I'm trying to figure out how to save an e-mail attachment from a POP3
> mailbox.  I've scoured the web, but -none- of the examples I have
> found have actually worked.  For instance, in this example:
> http://groups.google.com/group/comp.lang.python/browse_thread/thread/8423cad79ff21730/0d8922943a164ccf?lnk=gst&q=email+attachment#0d8922943a164ccf,
> fn is always None, but the e-mail -does- have an attachment (an xml
> file).
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>   
Try attached (caution *not* tested, I just cut and pasted it from a
larger script I use (it should work :) ).

I have used a similar method quite successfully.

HTH

Regards

Nicolaas

-- 

The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle. 


import mimetypes, email

def GetMailRaw (self, msg = {}):
""" Returns full email message in textformat."""
mailrawtext = ''
for line in msg:
mailrawtext += line
mailrawtext += '\n'

return str( mailrawtext )

def GetAttachments (self,  mail ):
""" This function is recursive, if the message contains
multipart message the function is recursively called to
get all the attachments"""

if ( not mail.is_multipart()):
print "NOTE: THIS DOCUMENT IS NOT MULTIPART - NO ATTACHMENTS TO PARSE."
return "NOT_MULTIPART"

partsThatAreAttachments = [] #empty list
index = 0

list = mail.get_payload()

# End of recursion, the payload is a string
if type(list) == type(""):
return

for part in list:
maintype =  part.get_content_maintype()

	# If attachment - add to attachment list
	if ( maintype != "text" and maintype != "multipart" and maintype != "message"):
	# Also the message type is a kind of multipart
	partsThatAreAttachments.append(index)

	if (maintype == "multipart" or maintype == "message"):
	# If there are more attachments - get them
	self.GetAttachments (part)
	
	index = index + 1

allAttachments = {}
listParts = mail.get_payload() # parts of mail message
offset = 0

for indexOfAttachment in partsThatAreAttachments:
indexOfAttachment = indexOfAttachment - offset
#save the part to delete - in present working dir
filename = listParts[indexOfAttachment].get_filename()
if not filename:
ext = mimetypes.guess_extension(part.get_content_type())
if not ext:
#generic extension
ext = ".bin"
filename = "part-%03d%s" % ( indexOfAttachment , ext)

	# DEBUG
	# Save attachments to present working dir
	# fp = open (filename, "wb")
	# fp.write(listparts[indexofattachment].get_payload(decode=1))
	# fp.close()

	# Add attachment to attachment dictionary
	allAttachments.setdefault(filename, []).append(listParts[indexOfAttachment].get_payload ()) 

	del listParts[indexOfAttachment]
	offset = offset + 1

return allAttachments

mailraw = GetMailRaw(popresponse)
mail = email.message_from_string(mailraw)
attachments = GetAttachments(mail)
--
http://mail.python.org/mailman/listinfo/python-list

Re: Standard module for parsing emails?

2008-07-30 Thread Aspersieman
Phillip B Oldham wrote:
> If there isn't a standard library for parsing emails, is there one for
> connecting to a pop/imap resource and reading the mailbox?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>   
The search [1] yielded these results:
1) http://docs.python.org/lib/module-email.html
2)
http://www.devshed.com/c/a/Python/Python-Email-Libraries-SMTP-and-Email-Parsing/

I have used the email module very successfully.

Also you can try the following to connect to mailboxes:
1) poplib
2) smtplib

For parsing the mails I would recommend pyparsing.


[1]
http://www.google.com/search?client=opera&rls=en&q=python+email&sourceid=opera&ie=utf-8&oe=utf-8

Regards

Nicolaas

-- 

The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle. 


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


Re: Autocompletion and Interactive Tables in a Python IDE

2008-07-24 Thread Aspersieman

>
> On Jul 24, 4:10 am, Aspersieman <[EMAIL PROTECTED]> wrote:
>   
>> Anthony wrote:
>> 
>>> Hi, I'm a FoxPro programmer, but I want to learn python before it's
>>> too late.  I do a lot of statistical programming, so I import SPSS
>>> into python.  In my opinion, the best features of Visual FoxPro 9.0
>>> were:
>>> a) Intellisense (tells you what classes/methods are available and what
>>> variables go into a function)
>>> b) Code Completion (guesses your code after four letters)
>>> c) Data-Orientation; multiple data sessions can be open, data can be
>>> viewed easily
>>>   
>>> Python's IDLE has only half of the first of these features.  I did a
>>> lot of searching and found the PyDev extensions for Eclipse's Python
>>> IDE, and found that they've got Intellisense.  I'm still missing b and
>>> c, and am getting extremely frustrated programming so slowly..
>>>   
>>> So two questions:
>>> Is there any package, gui, IDE, anything that will do FoxPro-style
>>> code completion?  If it works in Eclipse, even better..
>>> I can't find a good screenshot, but here's a better description:
>>> You type "BROW" and it pops up a window that says "BROWSE" ..at this
>>> point if you hit enter it completes the word..
>>>   
>>> and
>>>   
>>> How can I view open SPSS data in one of the Python GUIs?  Again,
>>> Eclipse would be the preference.
>>> Here's an example of how I'd like to browse the data:
>>> http://www.vfpconversion.com/ArticleImage.aspx?QuickID=0209071&Image=...
>>> I don't want to have to switch back and forth between Python and SPSS
>>> while I'm programming; I just want to stay in one of them..
>>>   
>>> What can I do?  I feel extremely inefficient when I don't have these
>>> three features..
>>>   
>>> Thanks in advance.
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>>   
>> You might want to try vim. It has a steep learning curve, but definitely
>> increases productivity _alot_.
>>
>> Here is a tutorial on setting up vim with :
>> 1) Code completion (intellisense) - including tooltips (!!!)
>> 2) Jump between your python code and the python class libraries.
>> 3) Syntax checking
>> 4) A handy source browser
>> 5) Debugging (using pdb)
>> 6) [All the other vim goodies - already included]
>> Above instructions available 
>> herehttp://blog.sontek.net/2008/05/11/python-with-a-modular-ide-vim/
>>
>> I have been using the above setup for a while and find it superior to
>> _any_ IDE I've ever worked with.
>>
>> I'm not sure what you mean by 'Data-Orientation' but I'm sure there's a
>> suitable alternative/replacement for it in vim.
>>
>> Regards
>>
>> Nicolaas
>>
>> --
>> 
Anthony wrote:
> FoxPro is data-oriented, which means that at any time you have any
> number of data sets open in the workspace and browse them immediately
> by running one line of code in the command window.  It's a really
> important feature in terms of efficiency; I don't want to have to move
> back and forth between SPSS and an IDE when I'm figuring out what code
> to write, that takes six keystrokes for what FoxPro can do in one.
> Again, here's what the BROWSE command presents:
>
> http://www.vfpconversion.com/ArticleImage.aspx?QuickID=0209071&Image=vfptoolkit_figure02.tif
>
>
> Does VIM have the capability to keep data open?  --  Do any of these
> IDEs have this browse capability??
I see what you mean by 'Data Oriented', however I'm not aware of such a
'data set' persistence functionality in vim. You can set up a similar
(to FoxPro) environment using DBExt [1] plugin in vim and by using its
(vims') built-in session functionality. To set up dbext for FoxPro in
vim you might need to use ODBC but it should be quite straight forward
provided you read the help.

I work on SQL Server (using python and vim) and frequently have many
queries result sets open that I'm busy with. When I have to go, all I do
is save my session in vim. When I return the next day, I open the
session, and it there I have all the queries (not the data sets they
return (however you can save that too)) and scripts etc, I was working
on. To execute a query (even one embedded in some python code) I merely
select the lines the query is on and type the key-mapping (

Re: Autocompletion and Interactive Tables in a Python IDE

2008-07-24 Thread Aspersieman
Anthony wrote:
> Hi, I'm a FoxPro programmer, but I want to learn python before it's
> too late.  I do a lot of statistical programming, so I import SPSS
> into python.  In my opinion, the best features of Visual FoxPro 9.0
> were:
> a) Intellisense (tells you what classes/methods are available and what
> variables go into a function)
> b) Code Completion (guesses your code after four letters)
> c) Data-Orientation; multiple data sessions can be open, data can be
> viewed easily
>
> Python's IDLE has only half of the first of these features.  I did a
> lot of searching and found the PyDev extensions for Eclipse's Python
> IDE, and found that they've got Intellisense.  I'm still missing b and
> c, and am getting extremely frustrated programming so slowly..
>
> So two questions:
> Is there any package, gui, IDE, anything that will do FoxPro-style
> code completion?  If it works in Eclipse, even better..
> I can't find a good screenshot, but here's a better description:
> You type "BROW" and it pops up a window that says "BROWSE" ..at this
> point if you hit enter it completes the word..
>
> and
>
> How can I view open SPSS data in one of the Python GUIs?  Again,
> Eclipse would be the preference.
> Here's an example of how I'd like to browse the data:
> http://www.vfpconversion.com/ArticleImage.aspx?QuickID=0209071&Image=vfptoolkit_figure02.tif
> I don't want to have to switch back and forth between Python and SPSS
> while I'm programming; I just want to stay in one of them..
>
> What can I do?  I feel extremely inefficient when I don't have these
> three features..
>
> Thanks in advance.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>   
You might want to try vim. It has a steep learning curve, but definitely
increases productivity _alot_.

Here is a tutorial on setting up vim with :
1) Code completion (intellisense) - including tooltips (!!!)
2) Jump between your python code and the python class libraries.
3) Syntax checking
4) A handy source browser
5) Debugging (using pdb)
6) [All the other vim goodies - already included]
Above instructions available here
http://blog.sontek.net/2008/05/11/python-with-a-modular-ide-vim/

I have been using the above setup for a while and find it superior to
_any_ IDE I've ever worked with.

I'm not sure what you mean by 'Data-Orientation' but I'm sure there's a
suitable alternative/replacement for it in vim.

Regards

Nicolaas

-- 

The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle. 


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


Re: Freesoftware for auto/intelligent code completing in Python

2008-07-04 Thread Aspersieman

Jeroen Ruigrok van der Werven wrote:

-On [20080630 23:51], Ali Servet Dönmez ([EMAIL PROTECTED]) wrote:
  

This could be an extension, a plugin, an Emacs mode, a new editor or
even a brand new huge all-fancy IDE, I don't care, but what am I
missing here?



Vim's omnicomplete (CTRL-X CTRL-O).

See :help omnifunc within vim.

  
I find Vim with ctags, omnicomplete and calltip support the BEST I've 
tried so far. And I've tried many.


Here's a tutorial on setting this up.
   http://blog.sontek.net/2008/05/11/python-with-a-modular-ide-vim/

Regards

Nicol

--

The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle. 



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

Re: IDE on the level of Eclipse or DEVc++?

2008-06-25 Thread Aspersieman

David wrote:

Rich Healey wrote:


I don't want to start a flamewar.

But I like vim.


Hi Rich, could I take a look at your .vimrc , the python stuff.
thanks
--
http://mail.python.org/mailman/listinfo/python-list


Try this :
http://blog.sontek.net/2008/05/11/python-with-a-modular-ide-vim/

Nicol

--

The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle. 



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


Re: don't make it worse! - was Re: SPAM

2008-06-20 Thread Aspersieman




Michael Torrie wrote:

  Aspersieman wrote:
  
  
SPAM

  
  
Obviously.  Please refrain from replying to the SPAM on this list.  It
just makes the problem worse.

Thanks.

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

  

ErrrOk.

I read somewhere that replying to potential spam with 'SPAM' in subject
will add it (the message sender you are replying to) to google's spam
filters. Can't find the link now though.

Sorry though, if doing this didn't help - or made it worse. :)

Nicol

-- 

The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle. 




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

SPAM

2008-06-19 Thread Aspersieman

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


SPAM

2008-06-19 Thread Aspersieman

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


Re: send yield

2008-05-16 Thread Aspersieman

castironpi wrote:

On May 15, 7:16 pm, castironpi <[EMAIL PROTECTED]> wrote:
  

On May 15, 6:43 pm, castironpi <[EMAIL PROTECTED]> wrote:







On May 15, 6:16 pm, castironpi <[EMAIL PROTECTED]> wrote:
  

On May 15, 4:28 pm, "[EMAIL PROTECTED]"

<[EMAIL PROTECTED]> wrote:


On 15 mai, 16:40, castironpi <[EMAIL PROTECTED]> wrote:
  

On May 15, 9:26 am, "Dan Upton" <[EMAIL PROTECTED]> wrote:


On Thu, May 15, 2008 at 9:32 AM, castironpi <[EMAIL PROTECTED]> wrote:
  

Why can't I write this?
--


Because your antecedent is undefined?
  

Of the two ways to play, just to say #define this per se would be a
bad move, but that's one that comes from the wrong group.  #define is
a big scary macro, that python hasn't been using; it's the one-line
typo.  Instance:

#define life1 Tron( drive.SIZE[ 0 ]/ 2, drive.SIZE[ 1 ]/ 2 )

Use it to render planes in solids.

Back about 'this', I honestly hadn't remembered 'til this time, when I

got a chance to reread the subject.  Plus I keep ditching my radio.


Jesus H. Christ. This really sounds like my mother in law. Scary,
definitively.- Hide quoted text -
  
- Show quoted text -
  

Definitely.  But, due, I forgot to complete an example.


#define life1 Tron( drive.SIZE[ 0 ]/ 2, drive.SIZE[ 1 ]/ 2 )


in C.  Python:

life1= 'Tron( drive.SIZE[ 0 ]/ 2, drive.SIZE[ 1 ]/ 2 )'

exec( life1 )

Where does it go?- Hide quoted text -

- Show quoted text -


I'm supposed to talk about an entropy pool game.  You can tunnel.- Hide quoted 
text -
  
- Show quoted text -
  

If I had a send-parachute, would all you need be yield?  Let's drop
graphics.- Hide quoted text -

- Show quoted text -



My character is studying chord progressions.  I have right angles.
I'm on a laptop, and talking in the car is fine.
--
http://mail.python.org/mailman/listinfo/python-list

  
My olive grove gave birth to many world war I biplanes I think I 
need more salt.


This thread gave me hope...

--

The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle. 



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


Re: Need to install Python in windows 32 bit processor

2008-05-13 Thread Aspersieman




[EMAIL PROTECTED] wrote:

  
  
  Hi people, 
   I am working with windows32 bit processor machine.   
  I want to install Python in my machine. 
  I am not able to get the preferable installer  for installing
python. 
  Can you tell, Which windows installer is preferable for
windows32 bit processor? 
  

http://www.python.org/ftp/python/2.5.2/python-2.5.2.msi

Regards

Nicol
-- 

The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle. 




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

Running compiled windows service python script

2008-05-13 Thread Aspersieman

Hi All

I have a windows service (attached file). I basically just calls another 
script every 60 seconds. I can install, start and stop this service as 
expected with:

   ParseMailboxService.py install | start | stop

The problem is: if I create an exe of this script (all required modules 
are included in the exe) with gui2exe (a frontend to py2exe) I can 
install the service - but not start it. The error it returns is "Error 
starting service: The service did not respond to the start or control 
request in a timely fashion."


Is there something I need to additionally include in the compiled exe? I 
have manually included the following modules:

   * servicemanager
   * win32con
   * win32evtlogutil
   * win32serviceutil

I would greatly appreciate any help.

Regards

Nicol

--

The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle. 



#!/usr/bin/env python
import win32service
import win32serviceutil
import win32api
import win32con
import win32event
import win32evtlogutil
import os

class aservice(win32serviceutil.ServiceFramework):
_svc_name_ = "ParseMailBox"
_svc_display_name_ = "ParseMailbox - Monitors a POP mail box and parses its emails and attachments."

def __init__(self,args):
win32serviceutil.ServiceFramework.__init__(self,args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

def SvcDoRun(self):
pathtoparsemailbox = "C:\\ParseMailbox\\ParseMailbox.exe"
import servicemanager
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,\
  servicemanager.PYS_SERVICE_STARTED,\
  (self._svc_name_, '')) 

self.timeout = 6 # 60 Seconds
while 1:
# Wait for service stop signal, if I timeout, loop again
rc = win32event.WaitForSingleObject(self.hWaitStop, self.timeout) 
# Check to see if self.hWaitStop happened
if rc == win32event.WAIT_OBJECT_0:
# Stop signal encountered
break
else:
stdin, stdout, stderr = os.popen3( pathtoparsemailbox )
parsemailboxresult = stdout.read()
parsemailboxerrors = stderr.read()

if parsemailboxerrors.strip() != "":
servicemanager.LogErrorMsg("An error occurred when running ParseMailbox (Please see ServiceLog.log for more details):\n" + parsemailboxerrors)

stdin.close(); stdout.close(); stderr.close()

# Only return from SvcDoRun when you wish to stop
return

def SvcStop(self):
# Before we do anything, tell Service Control Manager we are starting the stop process. 
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
return 

def ctrlHandler(ctrlType):
return True

if __name__ == '__main__':
win32api.SetConsoleCtrlHandler(ctrlHandler, True)
win32serviceutil.HandleCommandLine(aservice)
--
http://mail.python.org/mailman/listinfo/python-list

Re: Python and the Bartender

2008-05-12 Thread Aspersieman

[EMAIL PROTECTED] wrote:

Incidentally, now that everyone knows English, writer would like to
critique his behavior.  I have leaned to the group for approval, at
times by disparaging the efforts of others, but other times not.  I
have expressed negative emotion.  Is anyone in earshot getting work
done that I am interfering with?

Otherwise, I might start telling jokes.

Sincerely,
Two For Bartenders.

P.S.  Please don't write the movies.
--
http://mail.python.org/mailman/listinfo/python-list

  

Huh?

Nicol

--

The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle. 



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


Re: POP connection timeout.

2008-05-08 Thread Aspersieman

Gabriel Genellina wrote:

Use socket.setdefaulttimeout(timeout_in_seconds) before you create the POP3 
object; this value will be used by the initial connect. Once it is connected, 
you can set a different timeout for retrieving mail using 
pop.sock.settimeout(...)
Note that setdefaulttimeout applies to ALL subsequent socket operations, not 
only using poplib.


  

Fantastic! This works thanks.

Nicol

--

The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle. 



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


Parsing Email 'References' header.

2008-05-08 Thread Aspersieman

Hi

I have a python script that parses email headers to extract information 
from them. I need to get the _last_ messageid in the 'References' field 
(http://cr.yp.to/immhf/thread.html) to create a threaded view of these 
emails (these messageid's are stored in a database).


Now, I can easily access the 'References' field using the python 'email' 
module, but I need a regular expression to get the last messageid in the 
'References' field.


Here's what I have so far:

rx_lastmesgid = re.compile(r"(<.+>$)")
lastmesgid = "".join( filter( rx_lastmesgid.match, parentid ) ) # 
parentid's value is 
eg:"<[EMAIL PROTECTED]><[EMAIL PROTECTED]><[EMAIL PROTECTED]><[EMAIL PROTECTED]><[EMAIL PROTECTED]>"

lastmesgid = "".join( filter( rx_lastmesgid.match, parentid ) )


I need it to return "<[EMAIL PROTECTED]>"

Can anyone help?

Thanks

Nicol

--

The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle. 



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


POP connection timeout.

2008-05-08 Thread Aspersieman

Hi All

I have written an application that queries a POP mailbox and 
downloads messages. When the application tries to connect to the mail 
server, but takes too long (eg. longer than 60 seconds) I want to have 
it time out.


Something like

try:
  pop = poplib.POP3(POPHOST, POPPORT)
except someerror, err:
  print "Connecting to mail box has timed out:\n", err

I know that in python 2.5 I could pass an additional timeout parameter 
to the above statement ( ie: pop = poplib.POP3(POPHOST, POPPORT, 
TIMEOUTINSECONDS), but I am using python 2.4.


Can anyone help me implement this timeout functionality.

Regards

Nicol
--

The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle. 






--

The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle. 



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


POP connection timeout.

2008-05-08 Thread Aspersieman

Hi All

I am have written an application that queries a POP mailbox and 
downloads messages. When the application tries to connect to the mail 
server, but takes too long (eg. longer than 60 seconds) I want to have 
it time out.


Something like

try:
   pop = poplib.POP3(POPHOST, POPPORT)
except someerror, err:
   print "Connecting to mail box has timed out:\n", err

I know that in python 2.5 I could pass an additional timeout parameter 
to the above statement ( ie: pop = poplib.POP3(POPHOST, POPPORT, 
TIMEOUTINSECONDS), but I am using python 2.4.


Can anyone help me implement this timeout functionality.

Regards

Nicol
--

The three things to remember about Llamas:
1) They are harmless
2) They are deadly
3) They are made of lava, and thus nice to cuddle. 



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