Re: [Tutor] exit handler for C extension module

2010-01-18 Thread Shuying Wang
I found what I was after, right after I posted to this list. It's
Py_AtExit. I'm accessing an old, unsupported database using it's C
API. I've tried using Cython but found it hard to get my head around
and I'm finding it somewhat easier to just write by hand.

On Mon, Jan 18, 2010 at 6:40 PM, Stefan Behnel  wrote:
>> What would be an atexit equivalent for a C extension module? When my
>> extension module is unloaded, I would like some clean up functions to
>> be called from an external c library. I've had a look at the C
>> extension guide but I can't find anything like that,
>
> I'm not aware of anything special here. Just use the "atexit" module itself
> and register a Python function. At least, that's what we do in Cython for
> any module level cleanup.
>
> You may also consider adding some hints on what you want to use it for,
> maybe there is some support for your actual use case.
>
> Stefan
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] adding more text to a file

2010-01-18 Thread wesley chun
On Sun, Jan 17, 2010 at 5:19 PM, Alan Gauld  wrote:
>
> "Magnus Kriel"  wrote
>
>> It might be that when you create a file for the first time with 'a', that
>> it
>> will through an exception. So you will have to try with 'w', and if there
>> is
>> an exception, you know the file does not exist and you will have to create
>> the file for the first time with 'w'.
>
> That should not happen. If there is no file 'a' will act like 'w'


alan is correct. with 'a', if a file doesn't exist, it will create it
and open it for write. if it does exist, it will go to the current EOF
and open it for write starting from that point. the only time 'a'
throws an exception is if the file cannot be opened, e.g., it's on a
network drive that isn't there, no perms on that filesystem, etc.

-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Python Web Development with Django", Addison Wesley, (c) 2009
http://withdjango.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] exit handler for C extension module

2010-01-18 Thread Stefan Behnel
Shuying Wang, 18.01.2010 08:58:
> I found what I was after, right after I posted to this list. It's
> Py_AtExit. I'm accessing an old, unsupported database using it's C
> API.

I didn't write the respective code in Cython, but there's a comment next to
it saying

/* Don't use Py_AtExit because that has a 32-call limit
 * and is called after python finalization. */

So Py_AtExit() may or may not be what you are looking for.

Also note that Py3 has a C-API mechanism for safely cleaning up (and
potentially unloading) modules, which likely is what you are looking for
anyway.


> I've tried using Cython but found it hard to get my head around
> and I'm finding it somewhat easier to just write by hand.

Personally, I find it a matter of developer time (basically "why write C
when you can write Python?"), but your mileage may vary.

Stefan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] smtp project

2010-01-18 Thread Adam Bark
2010/1/17 Kirk Z Bailey 

> I am writing a script that will send an email message. This will run in a
> windows XP box. The box does not have a smtp server, so the script must
> crete not merely a smtp client to talk to a MTA, it must BE one for the
> duration of sending the message- then shut off, we don't need no bloody
> op0en relays here!
>
> I am RTFM and having some heavy sledding, can I get an Elmer on this?


This isn't quite what you're after but I wrote some code a while ago to find
the changes to a wiki in the day from an update RSS feed and then send an
email with these changes to a mailing list via a googlemail account. Anyway
there should be some useul code in it
http://cubesat.wikidot.com/wiki-change-emailer
HTH
Adam.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] smtp project

2010-01-18 Thread Kent Johnson
On Sun, Jan 17, 2010 at 9:57 PM, Kirk Z Bailey  wrote:

> There is no smtp server available, these are the cards I am delt; can you
> advise on how to play them?

A couple of possibilities:
- I'm no expert on SMTP but don't the MTAs talk SMTP to each other on
port 25? Could you use smtplib to talk to the remote MTA on port 25?

- The std lib contains a simple SMTP server in smtpd.py

- Lamson is a more robust SMTP server
http://lamsonproject.org/

- Twisted has SMTP support
http://twistedmatrix.com/trac/wiki/TwistedMail

Kent

PS Please Reply All to reply on list.

> Kent Johnson wrote:
>>
>> On Sun, Jan 17, 2010 at 3:45 PM, Kirk Z Bailey 
>> wrote:
>>>
>>> I am writing a script that will send an email message. This will run in a
>>> windows XP box. The box does not have a smtp server, so the script must
>>> crete not merely a smtp client to talk to a MTA, it must BE one for the
>>> duration of sending the message- then shut off, we don't need no bloody
>>> op0en relays here!
>>
>> Is there no SMTP server available on another machine? Can you send
>> email from a regular email client (e.g. Thunderbird)?
>>
>>> I am RTFM and having some heavy sledding, can I get an Elmer on this?
>>
>> An Elmer?
>>
>> Kent
>>
>>
>
> --
> end
>
> Very Truly yours,
>                 - Kirk Bailey,
>                   Largo Florida
>
>                       kniht
>                      +-+
>                      | BOX |
>                      +-+
>                       think
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] adding more text to a file

2010-01-18 Thread Modulok
If you're using this as an interactive command to help you populate a
database, as you appear to be, don't open the file more than once. As
previously suggested you should also put all your strings together and
then write them to the database in one go.

I don't know if you've thought about this yet, but you'll need a way
to stop when you're done inputing names and ages! Here are two
thoughts you can look into: 1) Check for a special character (or lack
thereof). For example, if the fields are blank you could exit the loop
using the 'break' statement. Or 2) Catching a 'KeyboardInterrupt'
exception using the 'try...except' statements. Without doing it for
you, (I assume this is homework) these are some suggested changes:

out_file = open('persons.txt', 'w')
while True:
name = raw_input("What is the name: ")
age = raw_input("What is the age: ")
out_file.write("name:%s\nage: %s\n\n" (name, age))

# We'll never get this far unless we figure out a way to stop the loop!
out_file.close()


Keep at it and best of luck!
-Modulok-
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python workspace - IDE and version control

2010-01-18 Thread galaxywatcher
I want to share a couple of insights that I had getting started with  
Python that I did not come across in the literature all that often. I  
am discovering that there are two primary supporting tools needed in  
order to create an efficient and productive Python programming  
workspace: IDE and Version Control. I didn't realize at first how  
important these supporting tools for Python would be. If Python is  
your first programming language, you will have to learn how to use a  
good text editor or IDE (Integrated Development Environment). If you  
use textpad, it gets old very fast. I have chosen vim as my IDE and I  
added a few key plugins that I think help a lot (snipMate, surround,  
nerd-tree, and repeat).  I believe that snipMate is a plugin made  
specifically for Python users on vim. Among other features, it auto  
indents your code which is very nice.


So now that I can do some Python scripting, I started to notice that  
my scripts were not very organized. Collaboration of code is  
difficult. I had multiple copies of the same script in different  
directories on my computer, and I did not have a good way to really  
keep track. This is the wrong way. Version Control Systems are tried  
and true technologies for collaborating with others (or even yourself)  
on your code. After some research, I have decided to go with Git. I  
have never used version control before, so I don't know the  
distinctions of the various systems out there. I chose Git mainly  
because github.com is really great. Some MAJOR open source (and  
closed) projects are happening on there and you can download the open  
source code so very easily. I am told Mercurial is good too, Bazaar  
and SVN also came up in my research.


Obviously, no tool can think for you. The real programming work of  
course is going on in your brain. I am curious what combination of IDE  
and Version Control System you use and also perhaps, what other tools  
I should be looking at as well.


Thanks.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python workspace - IDE and version control

2010-01-18 Thread Alan Gauld


 wrote

order to create an efficient and productive Python programming 
workspace: IDE and Version Control.


Both important, although an IDE is perhaps a generous
description of vim! :-)

Obviously, no tool can think for you. The real programming work of 
course is going on in your brain. I am curious what combination of IDE 
and Version Control System you use and also perhaps, what other tools  I 
should be looking at as well.


I tend to use vim under cygwin (which gives me all the Unix tools) as the 
IDE.


I use plain old RCS for version control because its just me working on the 
code.


At work where we have parallel streams I use SVN (used to be Borland 
$tarTeam)

Because we use Eclipse at work I increasingly use Eclipse with PyDev as my
IDE for larger projects - its project support is very effective and I like
the debugger. Also, since I often integrate Java and Jython, Eclipse is 
ideal for

integrating a multi-source project, especially with a UML modelling plugin
added to capture the design.

Finally, I use Subclipse to integrate Eclipse with SVN.

Alan G. 



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python workspace - IDE and version control

2010-01-18 Thread Matthew Lee
I usually just use NetBeans or the Python IDLE.
I prefer to use NetBeans because it's easier to change and modify code and
test. And also because I like to use Jython.

Anything wrong with my setup?



On Tue, Jan 19, 2010 at 8:17 AM, Alan Gauld wrote:

>
>  wrote
>
>
> order to create an efficient and productive Python programming workspace:
>> IDE and Version Control.
>>
>
> Both important, although an IDE is perhaps a generous
> description of vim! :-)
>
>
> Obviously, no tool can think for you. The real programming work of course
>> is going on in your brain. I am curious what combination of IDE and Version
>> Control System you use and also perhaps, what other tools  I should be
>> looking at as well.
>>
>
> I tend to use vim under cygwin (which gives me all the Unix tools) as the
> IDE.
>
> I use plain old RCS for version control because its just me working on the
> code.
>
> At work where we have parallel streams I use SVN (used to be Borland
> $tarTeam)
> Because we use Eclipse at work I increasingly use Eclipse with PyDev as my
> IDE for larger projects - its project support is very effective and I like
> the debugger. Also, since I often integrate Java and Jython, Eclipse is
> ideal for
> integrating a multi-source project, especially with a UML modelling plugin
> added to capture the design.
>
> Finally, I use Subclipse to integrate Eclipse with SVN.
>
> Alan G.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python workspace - IDE and version control

2010-01-18 Thread Alan Gauld


"Matthew Lee"  wrote


I usually just use NetBeans or the Python IDLE.
I prefer to use NetBeans because it's easier to change and modify code 
and

test. And also because I like to use Jython.

Anything wrong with my setup?


If it works for you then its fine.
IDEs, editors etc are all very personal choices and everyone is different.
I used Netbeans for a while and preferred it to Eclipse at the time, but I 
use

Eclipse because its what we have to use at work and consistency outweighs
the slight advantages I found in Netneans. If you don;t have that 
constraint

use whatever you find works best for you!

Alan G 



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python workspace - IDE and version control

2010-01-18 Thread muhamed niyas
I am using Netbeans, it has many features.
The following IDEs i used before Netbeanse
Anjuta, Komodo, python IDLE, etc..
There is a python plugin in Netbease and also it has subversion integrated.



On Tue, Jan 19, 2010 at 5:59 AM, Alan Gauld wrote:

>
> "Matthew Lee"  wrote
>
>
>  I usually just use NetBeans or the Python IDLE.
>> I prefer to use NetBeans because it's easier to change and modify code and
>> test. And also because I like to use Jython.
>>
>> Anything wrong with my setup?
>>
>
> If it works for you then its fine.
> IDEs, editors etc are all very personal choices and everyone is different.
> I used Netbeans for a while and preferred it to Eclipse at the time, but I
> use
> Eclipse because its what we have to use at work and consistency outweighs
> the slight advantages I found in Netneans. If you don;t have that
> constraint
> use whatever you find works best for you!
>
>
> Alan G
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Thanks & Best Regards,

Muhamed Niyas C
(NuCore Software Solutions Pvt Ltd)
Mobile: +91 9447 468825
URL: www.nucoreindia.com
Email: ni...@nucoreindia.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Contribution to Opensource

2010-01-18 Thread nikunj badjatya
Hi,
I recently joined this mailing list so as to improve my knowledge on Python.
Its been 4 months I am using Python. So I decided to contribute to any Open
source project. Can you help me on how to proceed on this,  Whom to contact
etc.

Thanks,

Nikunj Badjatya
BTech
Bangalore, India
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor