Re: [Tutor] 'root' dir of a package from within the package ?
On Mon, 8 Jan 2007 19:24:37 + Dave S <[EMAIL PROTECTED]> wrote: > Hi all, > > I have written a python package, which works fine, the 'root' directory > is 'my_app' with sub directories within in, complete with there __init__.py > files. > > I need to work out the path to the root directory from within the app, > os.path > gives me pythons path! - oh and its in XP. > > Any suggestions ? > Hi Dave, app_root = os.path.abspath(sys.path[0]) or, within the main executable .py file, app_root = os.path.abspath(os.path.dirname(__file__)) should do the trick. I hope this helps Michael ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] is gotchas?
Hugo González Monteverde wrote: >> Hmmm! Hmmm! >> Lookee here: >> ## console session >> >>> a=[1,2] >> >>> b=[1,2] >> >>> a is b >> False >> >>> c='1' ## one byte >> >>> d='1' ## one byte >> >>> c is d >> True >> >>> c='1,2' >> >>> d='1,2' >> >>> c is d >> False >> >> The Hmmm! is emmitted because I'm thinking that if everything is an >> object in python, then why does `c is d` evaluate to True when >> the assigned value is 1 byte and evaluate to False when the assigned >> value is more that 1 byte? > > One and two byte strings are currently optimized in cPython as the same > object, referenced multiple times. It's not just one-byte strings; I think any string that can be a Python identifier is interned and will always be the same string. In [1]: a='abcd' In [2]: b='abcd' In [3]: a is b Out[3]: True > > Note that this is not to be relied upon! Jython, Ironpython, Python3000 > or cPython itself may break it! Right. But why do you even care? I don't think I have ever written code that compares strings using 'is'; just use ==. > > Still cannot find a reference doc for this Probably the source code will be the only reference, this is an implementation detail. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 35, Issue 27
i have a clarification regarding built in function,in some scripts it is being used and it is give n: if _name_ == '_main_' why this is being used in the scripts? On 1/9/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: Send Tutor mailing list submissions to tutor@python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/tutor or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than "Re: Contents of Tutor digest..." Today's Topics: 1. Re: Need help with rewriting script to use Decimal module (Dick Moores) 2. import glob.glob('*.py') (J?nos Juh?sz) 3. Re: import glob.glob('*.py') (Kent Johnson) 4. Apologies... (Tim Golden) 5. 'root' dir of a package from within the package ? (Dave S) 6. Re: is gotchas? (Hugo Gonz?lez Monteverde) 7. Re: 'root' dir of a package from within the package ? (Michael Lange) -- Message: 1 Date: Mon, 08 Jan 2007 04:20:24 -0800 From: Dick Moores <[EMAIL PROTECTED]> Subject: Re: [Tutor] Need help with rewriting script to use Decimal module To: Terry Carroll <[EMAIL PROTECTED]>, tutor@python.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset="us-ascii"; format=flowed At 06:32 PM 1/7/2007, Terry Carroll wrote: >I may add this algorithm to the cookbook. You should. Dick -- Message: 2 Date: Mon, 8 Jan 2007 13:56:23 +0100 From: J?nos Juh?sz <[EMAIL PROTECTED]> Subject: [Tutor] import glob.glob('*.py') To: tutor@python.org Message-ID: < [EMAIL PROTECTED]> Content-Type: text/plain; charset="US-ASCII" Hi All, I am playing with reportlab and I would like to make a directory where I can place all of my projects as ___.py files. A project file should be like this: test.py title="Test project" duedate = '2007-02-28' description = "description _" detailed=""" detaileddetaileddetaileddetaileddetaileddetaileddetailed detaileddetaileddetaileddetaileddetaileddetaileddetailed detaileddetaileddetaileddetaileddetaileddetaileddetailed detaileddetaileddetaileddetaileddetaileddetaileddetailed detaileddetaileddetaileddetaileddetaileddetaileddetailed """ test.py I plan to make a python script, that collect all the projectfiles from that folder and render them as a report summary. I planned to import these files as modules like for filename in glob.glob('*.py'): if '_' in filename: continue import filename render(filename) Probably you have better ideas to do that. Yours sincerely, __ Janos Juhasz -- Message: 3 Date: Mon, 08 Jan 2007 08:38:42 -0500 From: Kent Johnson <[EMAIL PROTECTED]> Subject: Re: [Tutor] import glob.glob('*.py') To: J?nos Juh?sz <[EMAIL PROTECTED]> Cc: tutor@python.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=ISO-8859-1; format=flowed J?nos Juh?sz wrote: > I plan to make a python script, that collect all the projectfiles from > that folder and render them as a report summary. > I planned to import these files as modules like > > for filename in glob.glob('*.py'): > if '_' in filename: continue > import filename > render(filename) This won't work, the import statement does not take a variable as an argument. You need something like module = __import__(filename) render(module) You will want to take care that your modules don't have any side effects on import. > > Probably you have better ideas to do that. You might want to look at the existing Python document generation tools. There is a summary here (be sure to read the comments and the original post just below this one): http://www.voidspace.org.uk/python/weblog/arch_d7_2006_12_30.shtml#e599 In particular PythonDoc supports structured comments that are similar to what you outlined and has pluggable output generators that could be used to drive ReportLab. Kent -- Message: 4 Date: Mon, 08 Jan 2007 16:49:24 + From: Tim Golden <[EMAIL PROTECTED]> Subject: [Tutor] Apologies... To: tutor@python.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=ISO-8859-1; format=flowed ... my many apologies to the readers of the tutor list. I went away for a week without suspending delivery just as my company changed name - and decided to send an irritating response to anything directed at the old name. The list admin has very properly unsubscribed the old address (otherwise you'd be seeing loads more of the things!). Sorry again. Hope it didn't spoil your new year. TJG -- Message: 5 Date: Mon, 8 Jan 2007 19:24:37 + From: Dave S <[EMAIL PROTECTED]> Subject: [Tutor] 'root' dir of a package from within the p
Re: [Tutor] python Error:IndentationError: expected an indented block
hi .. i'm learning python .i have a book with examples. i did the examples for "if" and have the same errors... here is the simple code(two of them) >>> z=['ze','se'] >>> for s in z: ... if s=='ze': File "", line 2 if s=='ze': ^ IndentationError: expected an indented block >>> z=['ze','se'] >>> while s in z: ... if s=='ze': File "", line 2 if s=='ze': ^ IndentationError: expected an indented block why why :/ -- View this message in context: http://www.nabble.com/python-Error%3AIndentationError%3A-expected-an-indented-block-tf2596004.html#a8236580 Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python Error:IndentationError: expected an indented block
ziok wrote: > hi .. > > i'm learning python .i have a book with examples. i did the examples for > "if" and have the same errors... > here is the simple code(two of them) z=['ze','se'] for s in z: > ... if s=='ze': > File "", line 2 > if s=='ze': > ^ > IndentationError: expected an indented block Python uses indentation to define blocks. For example, to show which statements are controlled by a for or if statement, the controlled statements are indented. Your book should talk about this. So when typing these examples you need to indent the lines after the for, if or while. The indentation can be any consistent white space. Four spaces is a very common indent. When typing at the interactive prompt I usually use two spaces just because it's easier to type. Your code should look something like this: >>> z=['ze','se'] >>> for s in z: ... if s=='ze': ... print 'found ze' ... else: ... print 'not ze' Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 35, Issue 27
raghu raghu wrote: > i have a clarification regarding built in function,in some scripts it is > being used and it is give n: if _name_ == '_main_' > why this is being used in the scripts? This is a way to include test code that runs if the module is run as a main program, but not if the module is imported. Here is some more explanation: http://diveintopython.org/getting_to_know_python/testing_modules.html http://pyfaq.infogami.com/tutor-what-is-if-name-main-for Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about __name__ global variable (Was: Tutor Digest, Vol 35, Issue 27)
raghu raghu wrote: > i have a clarification regarding built in function,in some scripts it > is being used and it is give n: if _name_ == '_main_' > why this is being used in the scripts? The global variable __name__ is equal to '__main__' when the python script is run. If the script is imported, __name__ is something other than '__main__' (not sure what.) So by checking if __name__ == '__main__' we can ensure that our code can work both as a standalone script and as a module. For example: #test-script.py import random def someFunction(a): return a * random.randrange(100) if __name__ == "__main__": print "The number 42 passed to someFunction is: " + someFunction(42) #- If we want to use the function someFunction from test-script.py in a different file, the 'main' part won't be run. # import test-script print "The number 3 passed to someFunction is: " + someFunction(3) #- if the 'if __name__ == '__main__' ' test weren't in the original test-script.py, the 42 version of the print statement would be run whenever someone imported it. HTH, -Luke ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] feeding data to subprocess exes and getting results without writing files
Hi there, I can easily use the subprocess module to run a separate exe from within MyScript.py.. e.g. import subprocess process=subprocess.Popen("myprog.exe -i inputfile.txt -o outputfile.txt") ..and that's just fine as far as it goes, if I don't mind creating 'inputfile.txt' first, and reading 'outputfile.txt' afterward. But what if I do mind? I'm trying to do something like.. stdin="my input string" process=subprocess.Popen("myprog.exe -i stdin -o stdout") # (infact these are the default args for -i and -o, so it seems like myprog.exe can be used this way) myresults=stdout I just can't wrap my head around stdin, stdout and the whole pipes thing, but there's got to be a relatively simple way to do this, surely? thanks for any help, Dave (relative newbie using PythonWin & Python 2.4) This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] feeding data to subprocess exes and getting results without writing files
Barton David schrieb: > I just can't wrap my head around stdin, stdout and the whole pipes > thing, but there's got to be a relatively simple way to do this, surely? You have to distinguish between three different concepts: 1) file names 2) file objects 3) file contents 1) Is just a string with some identifier (the file path). To use a file with that identifier in Python, you have to create a file object from it by using the builtin 'open' function. 2) File objects are builtin Python objects that are usually created by the 'open' function or returned by some other function. There are a few file objects that are already opened and accessible to your Python program. These are sys.stdin, sys.stderr and sys.stdout. They are file objects, *not* strings representing the (non-existant) file name or file content! 3) File contents are just represented by binary strings in Python. You read/write them with the appropriate methods of file objects. ==> The subprocess.Popen constructor expects *file objects* not strings for its 'stdin' and 'stdout' arguments. Read the documentation of subprocess.Popen very carefully again (ignore references to file *descriptors*). BTW: a pipe is just an object or function that reads from one file object and writes to another. Chris ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] smtplib starttls() error
On 1/8/07, Olen <[EMAIL PROTECTED]> wrote: > I have also looked in all the documentation python 2.4.3 files I downloaded > and this points out that I should have install the socket.ssl() > my question is that is how do I install the > > socket.ssl() > > thank you > > ennma > On 1/8/07, olen88 <[EMAIL PROTECTED]> wrote: > > Hello, > > I was wondering if anyone could point me in the right direction > > my system info: > > Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)] on > > win32 > > > > as the subject says. starttls() returns the following error, > > > > reply, null = session.starttls(); > > File "C:\Python24\lib\smtplib.py", line 601, in starttls > > sslobj = socket.ssl(self.sock, keyfile, certfile) > > AttributeError: 'module' object has no attribute 'ssl' > > > > I tried, > > > > import socket > > > > socket.ssl(); > > > > same AttributeError exception was raised, so this confirmed that > > socket.py has no ssl attribute. > > > > what can I do about this, some answers I digged up suggest > > > > http://mail.python.org/pipermail/python-list/2003-June/207802.html > > > > but I am hasty about this suggestion, and wishes to consult to you all > > about what to do. > > > > Thank you > > > > ennma > > > > ___ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: smtplib starttls() error
-- Forwarded message -- From: Olen <[EMAIL PROTECTED]> Date: Jan 8, 2007 1:44 AM Subject: Re: [Tutor] smtplib starttls() error To: tutor@python.org I have also looked in all the documentation python 2.4.3 files I downloaded and this points out that I should have install the socket.ssl() my question is that is how do I install the socket.ssl() thank you ennma On 1/8/07, olen88 <[EMAIL PROTECTED]> wrote: > Hello, > I was wondering if anyone could point me in the right direction > my system info: > Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)] on > win32 > > as the subject says. starttls() returns the following error, > > reply, null = session.starttls(); > File "C:\Python24\lib\smtplib.py", line 601, in starttls > sslobj = socket.ssl(self.sock, keyfile, certfile) > AttributeError: 'module' object has no attribute 'ssl' > > I tried, > > import socket > > socket.ssl(); > > same AttributeError exception was raised, so this confirmed that > socket.py has no ssl attribute. > > what can I do about this, some answers I digged up suggest > > http://mail.python.org/pipermail/python-list/2003-June/207802.html > > but I am hasty about this suggestion, and wishes to consult to you all > about what to do. > > Thank you > > ennma > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Before I start
Hi, Before I jump into the investigation, I wanted to ask experts and get help/direction. I am looking to develop a simple web application. What would be my best approach. Thank you Raju __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Before I start
Hi, Before I jump into the investigation, I wanted to ask experts and get help/direction. I am looking to develop a simple web application. What would be my best approach? What package/s is good to explore? Need HTML GUI for Client (Qt plug-in may be ok). Server application with database Thank you Raju __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] smtplib starttls() error
olen88 wrote: > Hello, > I was wondering if anyone could point me in the right direction > my system info: > Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)] on > win32 > > as the subject says. starttls() returns the following error, > > reply, null = session.starttls(); > File "C:\Python24\lib\smtplib.py", line 601, in starttls > sslobj = socket.ssl(self.sock, keyfile, certfile) > AttributeError: 'module' object has no attribute 'ssl' > > I tried, > > import socket > > socket.ssl(); > > same AttributeError exception was raised, so this confirmed that > socket.py has no ssl attribute. Are you using the standard Python installer from python.org or something else? SSL support is a build option. It is included in the standard Python for Windows v2.3.5 and 2.4.4. Can you upgrade to the standard 2.4.4 distribution and see if that works? > > what can I do about this, some answers I digged up suggest > > http://mail.python.org/pipermail/python-list/2003-June/207802.html > > but I am hasty about this suggestion, and wishes to consult to you all > about what to do. I don't think that should be needed. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] question about pydev
hey there gents, i was wondering if anyone uses pydev ? its a plugin for eclipse. Has lots of cool stuffs, but i don't like the way it does code snippets, when i paste one that is kinda long, it messes up the indentation. anyone know a way around this ? i have posted this question on the pydev sourceforge list ( about 2 weeks ago ) and have not heard anything, so thought i would ask the folk most likely to be using it. thanks ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] smtplib starttls() error
On Tue, 9 Jan 2007, Kent Johnson wrote: > Are you using the standard Python installer from python.org or something > else? SSL support is a build option. It is included in the standard > Python for Windows v2.3.5 and 2.4.4. Can you upgrade to the standard > 2.4.4 distribution and see if that works? I'm guessing that Olen is using Activestate's distribution, which does not include SSL for export control reasons: ActivePython does not include SSL support. Why is this, and how can I add it? Here is an answer on python-list while discussing the differences between ActivePython and python.org's Python: http://mail.python.org/pipermail/python-list/2005-December/315754.html [http://mail.python.org/pipermail/python-list/2005-December/357227.html] ... - As Neil pointed out, ActivePython does not currently have SSL bindings (the _ssl module) that python.org's Python builds do. We are currently going through the legal hurdles so that we can include those. I expect that by or before the Python 2.5 timeframe we'll have _ssl in ActivePython. ... In the interim just plopping in the _ssl.pyd|so from either python.org's build or from your own build into ActivePython's lib-dynload directory will work to get ActivePython talking SSL. http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/faq.html#ext_ssl ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about __name__ global variable (Was: Tutor Digest, Vol 35, Issue 27)
> The global variable __name__ is equal to '__main__' when the python > script is run. > If the script is imported, __name__ is something other than '__main__' > (not sure what.) it will be the name of your module. so for foo.py, if you execute it (as a script), __name__ == '__main__', but if you 'import foo', __name__ == 'foo'. hope this helps! -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 http://corepython.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 http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] smtplib starttls() error
Hi Kent and Terry, Correct I am using Active state python,and did not read the full information about installations. Thank you for for the information. I just need to confirm something, In python when we "upgrade" we essentially install a new version of python , and we would be needing to install what ever custom packages we have previously installed right? thank you once again Olen On 1/9/07, Terry Carroll <[EMAIL PROTECTED]> wrote: > On Tue, 9 Jan 2007, Kent Johnson wrote: > > > Are you using the standard Python installer from python.org or something > > else? SSL support is a build option. It is included in the standard > > Python for Windows v2.3.5 and 2.4.4. Can you upgrade to the standard > > 2.4.4 distribution and see if that works? > > I'm guessing that Olen is using Activestate's distribution, which does not > include SSL for export control reasons: > >ActivePython does not include SSL support. Why is this, and how can I >add it? > >Here is an answer on python-list while discussing the differences >between ActivePython and python.org's Python: > > >http://mail.python.org/pipermail/python-list/2005-December/315754.html >[http://mail.python.org/pipermail/python-list/2005-December/357227.html] > >... >- As Neil pointed out, ActivePython does not currently have SSL > bindings (the _ssl module) that python.org's Python builds do. We > are currently going through the legal hurdles so that we can > include those. I expect that by or before the Python 2.5 > timeframe we'll have _ssl in ActivePython. >... > >In the interim just plopping in the _ssl.pyd|so from either >python.org's build or from your own build into ActivePython's >lib-dynload directory will work to get ActivePython talking SSL. > > http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/faq.html#ext_ssl > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor