Re: [Tutor] assignment statements in python
Kermit Rose wrote: > > Message: 1 > Date: Sun, 11 Jun 2006 06:58:39 -0400 > From: Kent Johnson <[EMAIL PROTECTED]> > Subject: Re: [Tutor] buggy bug in my program > Cc: tutor@python.org > > Assignment in Python is not a copy, it is a name binding. Assignment > creates a name for an object. If you assign the same object to two > names, they both are bound to the same thing. If the object is mutable, > like a list, changes to the object will be seen regardless of which name > you use to refer to it. > > ** > > I feel a little bit better now that I know that there is a reason for what > my > program did. > > However, I still don't have any idea how to copy values from one cell in > an array to the adjacent cell in the same array. You need to copy the value stored in the list, which is itself a list. > It must be possible, for otherwise, you could not sort an array. Actually sorting doesn't require copying the values in the list, it just requires moving values to different locations of the list. A list element is somewhat like a name - it is a reference to a value, not a container for a value. If you say a=[1,2,3] b=a then a and b refer to the same list. Likewise, if you say x=[ [1,2,3], [4,5,6] ] x[1] = x[0] then x[1] and x[0] refer to the same list. If you want x[1] (or b) to refer to a new list, you have to copy the old list: x[1] = x[0][:] list[:] is the slice of the list that goes from the beginning to the end - a copy. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python related mags
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi everyone, Does anyone know of any Python related magazines available that would be worth subscribing to? Ideally, a free one, but I would not object to a reasonably priced one either. I was able to find pyzine located at www.pyzine.com but it appears to be defunct. - -- Thank you, Andrew Robert Systems Architect Information Technologies MFS Investment Management Phone: 617-954-5882 E-mail: [EMAIL PROTECTED] Linux User Number: #201204 -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.1 (MingW32) Comment: GnuPT 2.7.2 iD8DBQFEjVWhDvn/4H0LjDwRAtsnAJwJ6I6elkmzCwmJUNC3CxDPxjR3bQCeOwL6 IMxn+qVOqe4uwuaCrGA8Qww= =hJPj -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Wondering is there a pyQT list
Hi, I was wondering if there is a pyqt list like the [EMAIL PROTECTED] list? Thanks John ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] connect to a remote machine - Linux
Thank you for the great explanation, Danny.. I was confused... Thank you all for your help! PatriciaOn 6/11/06, Danny Yoo <[EMAIL PROTECTED]> wrote: > I'm sorry. I think I didn't explain myself well. My problem is not with> the database.. The part I'm not sure how to do is connect to the remote> computer..Hi Patricia,There's some confusion here. Let's get that out in the open. It sounds like you have a remote server. That server provides login shellservice through ssh, and this login shell service runs on port 22, Ithink. But if your server is running MySQL, it is very likely that it provides network access to that MySQL database through port 3306.I think you believe that ssh login access is required to access MySQL onyour remote network server. But this is not necessarily true: one can access MySQL remotely without having a login shell account into themachine. That is, rather than: Client > Login through SSH > Execute mysql clientwhich is three steps, the conventional route here is: Client > Connect to networked MySQL using a database driver (MySQLdb)which is more direct.See: MySQLdb: http://sourceforge.net/projects/mysql-pythonas well as: http://www.devshed.com/c/a/Python/MySQL-Connectivity-With-Python/ However, this does mean that the remote MySQL server has to be set up witha separate MySQL username/password account. That is, MySQL keeps its ownset of usernames and passwords that can be separate from the shell logins.Also, mysqld --- the software that drives the MySQL server --- has to beenabled to work across tcp. That requirement sounds obvious enough, butit is not the default in the MySQL server installs I've seen lately, so double check this with your database system administrator. In short: youcan not automatically assume that having login access to the machine willgive you MySQL database access, and visa-versa.Does this make sense so far? > I read somewhere that os.popen would work, but I'm not sure if that will> do for meAlmost certainly no.popen is not for external database access. People have written databasedrivers to solve this problem for you already. It is perhaps possible to bend popen() in such a way to access MySQL, but this will involve anamount of work to get right, and there will be a lot of ways of getting itwrong. *grin*So I'd recommend changing this question from: "How do I get popen() to access MySQL across a remote interface?" to a more general: "How do Iconnect to MySQL from Python?" The link above to MySQLdb will give youthe software necessary to connect your client to a MySQL server, and the link to the Devshed article is a tutorial on how to use it effectively.Good luck! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] assignment statements in python
On Sun, 2006-06-11 at 22:14 -0400, Kermit Rose wrote: > Message: 1 > Date: Sun, 11 Jun 2006 06:58:39 -0400 > From: Kent Johnson <[EMAIL PROTECTED]> > Subject: Re: [Tutor] buggy bug in my program > Cc: tutor@python.org > > Assignment in Python is not a copy, it is a name binding. Assignment > creates a name for an object. If you assign the same object to two > names, they both are bound to the same thing. If the object is mutable, > like a list, changes to the object will be seen regardless of which name > you use to refer to it. > > ** In that case, is it possible to copy a variable by value, instead of by reference, in Python? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Odd traceback - invalid token when extracting contents of XML data element
Hi Everyone, Attached are three scripts that I intend to use for transporting a file via IBM's WebSphere MQSeries middle-ware. The sender script uses a regular expression to replace characters not [a-z][A-Z][0-9] or white space with their hex value equivalents. The purpose of this is to make the contents of a transported file viewable inside MQSeries queues. The attached code works just fine for transporting ASCII text files but it bombs with the following trace when run against binary files. Does anyone know why this might be occurring? Traceback (most recent call last): File "M:\MQ\MQ\Scripts\receiver.py", line 267, in ? receiver.run() File "M:\MQ\MQ\Scripts\receiver.py", line 110, in run self.get() File "M:\MQ\MQ\Scripts\receiver.py", line 139, in get tree = ElementTree(file=buff) File "C:\Python24\Lib\site-packages\elementtree\ElementTree.py", line 543, in __init__ self.parse(file) File "C:\Python24\Lib\site-packages\elementtree\ElementTree.py", line 583, in parse parser.feed(data) File "C:\Python24\Lib\site-packages\elementtree\ElementTree.py", line 1242, in feed self._parser.Parse(data, 0) xml.parsers.expat.ExpatError: not well-formed (invalid token): line 3, column 39 I think that a particular character is perhaps not being translated to ascii as required but I don't know which one it mught be. Part of the reason for this encoding mechanism is so that it plays nice with existing perl code already in place. Not my choice, but what can you do. Any help you can provide on this would be greatly appreciated. -- Thank you, Andrew Robert #!c:\python24\python # Program: sender.py # Authors: Andrew Robert and Dariusz Suchojad # # Function: To send files to an MQSeries Queue via a server connection # # # Module requirements not included with Python are ElementTree and Pymqi. # # Element tree can be found at http://effbot.org/downloads/#elementtree # # Pymqi can be found athttp://pymqi.sourceforge.net/ # # Logging with tie-ins to the NT event viewer require the Python Windows # extensions located at http://sourceforge.net/project/showfikes.php?group_id=78018 # # Conventions used in this program are that all queue managers and queues are upper case. # # # VerDate Programmer Modification # v1.0 - 05/09/06 AAR Initial release # v1.1 - 05/10/06 AAR Change how file is opened to rb # v1.2 - 05/11/06 AAR Modified to connect via server connections only # v1.3 - 05/11/06 AAR Added requirement to specify destination file name # v1.4 - 05/11/06 AAR Change value test logic to prevent usage of # empty string values # Removed test for exception on qmgr connect # Converted certain comment lines to doc strings # v1.5 - 05/13/06 AAR Added checksum generation of transmitted file # v1.6 - 05/14/06 AAR Checksum generation enhanced to better handle # large files # v1.7 - 05/15/06 AAR Added event logging to NT event application viewer. # This leverages built in date/time stamping as well # as presenting a central repository for all events # v1.8 - 05/15/06 AAR update logging logic, removing if/elif/else conditions # Added POSIX plaform support for logging events # v1.9 - 05/16/06 AAR Add ability to take command options from input file # v1.10 - 05/19/06 AAR Append python module library path to include ts-mqadm-d share # Farm out event logging, checksum, mailer to # separate/reusable modules stored on ts-mqadm-d share # temporarily removed ability to send mail or validate addressing # v1.11 - 05/19/06 AAR Move signal handling to external module and update code # references # v1.12 - 05/21/06 AAR Change file encoding from base64 to quopri methodology. # Quopri is an encoding strategy based on RFC 1521 for mime # v1.13 - 05/22/06 AAR Revert encoding structure back to base64. quopri structure # does not encode in XML well # v1.14 - 05/22/06 AAR Determine if input file is ascii or binary. adjust encoding # on file type # v1.15 - 05/26/06 AAR Add import of custom file encoder function # remove import of base64 module # remove call to base64 encoder # modify content element creation so that it is done in # place instead of as s
Re: [Tutor] assignment statements in python
>> Assignment in Python is not a copy, it is a name binding. Assignment >> creates a name for an object. If you assign the same object to two >> names, they both are bound to the same thing. If the object is mutable, >> like a list, changes to the object will be seen regardless of which >> name you use to refer to it. >> >> ** > > In that case, is it possible to copy a variable by value, instead of by > reference, in Python? The 'copy' module is available, http://www.python.org/doc/lib/module-copy.html So in a pinch, if we're really paranoid, we can pass copies of our argument values to a function. In general, though, a function should really document if it mutates its arguments, because that's generally a very rude thing to do unless it's the expected behavior. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] XML: Expletive Deleted
Kent, Danny, Lawrence, et. al. Thanks! I was kind of cringing as I sent this plaint/rant, but it seems I'm not the only one who has had trouble grokking DOM. I spanked the problem temporarily with regex, but can now actually fix it properly. Appreciate all the help!On 6/10/06, Kent Johnson <[EMAIL PROTECTED]> wrote: In my opinion the standard DOM models are the most awkward way to dealwith XML. If you are trying to get data from HTML on a web page, look atBeautifulSoup. For general XML processing, look at ElementTree. They are both simpler than DOM.http://www.crummy.com/software/BeautifulSoup/http://effbot.org/zone/element.htm Kent___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] assignment statements in python
On Mon, 2006-06-12 at 09:37 -0400, Kermit Rose wrote: > > From: Python > Date: 06/11/06 22:59:38 > To: Kermit Rose > Cc: Tutor Python > Subject: Re: [Tutor] assignment statements in python > > > The basic python objects: numbers, strings, and tuples are immutable and > can not be changed (mutated). > a = B = 3 > B = 4 # binds B to a different object with value 4 > # the object with value 3 is unchanged > print a > 3 > > ** > If I write > > a = 3 > a = 4 > a = 5 > > Are the objects containing 3 and 4 erased when they no longer have a name? Yes > > ** > > > > > Container objects such as lists and dictionaries can be changed in > place. > >>> a = B = [1,2,3] > >>> B.append(4) # changes (mutates) B > >>> print a > [1, 2, 3, 4] > > ** > > Good. Now I know a more efficient way to extend an array. > > I had been creating an entire new array, and equivalencing the old array to > it. > > ** > >> > > >>> B[2] = B[3] # positions 2 and 3 reference the same object > >>> print B > [1, 2, 4, 4] > >>> print a > [1, 2, 4, 4] > > ** > > I still don't know how to make it so that > > If B = [ 1,2,4,5] > > B.append(value of B[4]) There is no B[4] B[0] is 1 B[1] is 2 B[2] is 4 B[3] is 5 Perhaps you mean to search B looking for the value 4 and then append that value? index_of_4 = B.index(4) # returns index to location of first 4 B.append( B[index_of_4])# appends the 4 to the end of B > copy the value of B[2] into B[3] >>> import copy >>> B = [ 1,2,4,5] >>> B[3] = copy.copy(B[2]) >>> B [1, 2, 4, 4] Since 4 is immutable, there is no need to use the copy module, but it is there for when you need to make copies of an object. > copy the value 3 into B[2]. B[2] = 3# no need for a copy since 3 is immutable > > > Or, equivalently, > > If B = [1,2,4,5] > > Insert the value 3 between > B[1] and b[2], > >>> B = [ 1,2,4,5] >>> B.insert(2,3) # inserts 3 before B[2] >>> B [1, 2, 3, 4, 5] >>> help(B.insert) insert(...) L.insert(index, object) -- insert object before index (Use q to leave the help screen) > so that B > becomes > [1,2,3,4,5]. > > Kermit < [EMAIL PROTECTED] > > > > > > > > > ___ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor -- Lloyd Kvam Venix Corp ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] sorting in python
Message: 6 Date: Mon, 12 Jun 2006 05:59:16 -0400 From: Kent Johnson <[EMAIL PROTECTED]> Subject: Re: [Tutor] assignment statements in python Actually sorting doesn't require copying the values in the list, it just requires moving values to different locations of the list. * Yes. I wish to know how I can , for examplem, given B = [1,2,4,5], move B[3] to a position of newly created B[4], move B[2] to position of B[3] Assign value 3 to position B[2]. That is, I wish to insert the value 3, into it's sorted place within the already sorted list B. > A list element is somewhat like a name - it is a reference to a value, not a container for a value. If you say a=[1,2,3] B=a then a and B refer to the same list. Likewise, if you say x=[ [1,2,3], [4,5,6] ] x[1] = x[0] then x[1] and x[0] refer to the same list. *** >>> x = [ [1,2,3],[4,5,6]] >>> x [[1, 2, 3], [4, 5, 6]] >>> x[1] = x[0] >>> x [[1, 2, 3], [1, 2, 3]] >>> Needed to make sure I understood what would happen. Does the value [4,5,6] get erased at this point? If you want x[1] (or B) to refer to a new list, you have to copy the old list: x[1] = x[0][:] list[:] is the slice of the list that goes from the beginning to the end - a copy. * I missed the significance of the [:] slice until you explained it. So, now I could write my code as # to insert 3 between 2 and 4 in B = [1,2,4,5] B.append(B[3:3]) # I expected B[4] to have the value 5 at this point. # It is empty. Why? # So, I compensate by making the next line B[4] = B[3:3] # B[4] is still an empty list. Why? # I try B[4] = B[3] # That seemed to work. B[3] = B[2] # Now I try B[2] = 3 That worked. However, I don't see the difference between this code, and what I had before that did not work. Kermit < [EMAIL PROTECTED] > Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sorting in python
On Mon, 2006-06-12 at 11:26 -0400, Kermit Rose wrote: > # to insert 3 between 2 and 4 in > > B = [1,2,4,5] > > B.append(B[3:3]) >>> B[3:3] [] >>> B[3:4] [5] >>> B[0:1] [1] >>> B[:2] [1, 2] >>> B.append(B[3:3]) >>> B [1, 2, 4, 5, []] > > # I expected B[4] to have the value 5 at this point. > # It is empty. Why? You appended an empty list. Note that slice notation returns a list, so you would more commonly use B.extend(B[0:3]) to avoid nested lists. The number before the : is the index to include from The number after the : is the index to exclude Slices are half-open intervals. The lower-bound is included while the upper-bound is excluded. http://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF Provides an excellent justification for this approach (cited recently on this list) -- Lloyd Kvam Venix Corp ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] XML: Expletive Deleted (OT)
Alan, Ralph, et al: This is a little off-topic, I guess, being not directly related to Python. Oh, well. Here are a couple of personal opinions and a question about XML. > -Original Message- > Date: Sun, 11 Jun 2006 08:55:17 +0100 > From: "Alan Gauld" <[EMAIL PROTECTED]> > Subject: Re: [Tutor] Expletive Deleted > To: "Ralph H. Stoos Jr." <[EMAIL PROTECTED]>, > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; format=flowed; charset="iso-8859-1"; > reply-type=original > > > I think XML is a tool that allows non-programmers to look at > > structured > > data and have it a in human readable form that gives us a chance of > > understanding that structure. > > Thats not a great reason to choose a file format IMHO. > Tools can be written to display data in a readable format. > For example SQL can be used to view the data in a database. > File formats should be designed to store data, compactly > and with easy access. One reason to for choosing a human-readable format is the desire to visually confirm the correctness of the stored data and format. This can be invaluable when troubleshooting a bug involving stored data. If there is a tool between the user and the data, one must then rely upon the correctness of the tool to determine the correctness of the data. In a case like this, nothing beats the evidence of one's eyes, IMHO. In their book, "The Pragmatic Programmer: From Journeyman to Master" (Addison Wesley Professional), Andrew Hunt and David Thomas give another reason for storing data in human readable form: The problem with most binary formats is that the context necessary to understand the data is separate from the data itself. You are artificially divorcing the data from its meaning. The data may as well be encrypted; it is absolutely meaningless without the application logic to parse it. With plain text, however, you can achieve a self-describing data stream that is independent of the application that created it. Tip 20 Keep Knowledge in Plain Text > > The other strength that I can see is this: Once data is in this > > format, > > and a tool has been written to parse it, data can be added to the > > structure (more elements) and the original tool will not be broken > > by > > this. Whatever it is parsed for is found and the extra is ignored. > > But this is a very real plus point for XML. > And this IMHO is the biggest single reason for using it, if you have > data where the very structure itself is changing yet the same file > has to be readable by old and new clients then XML is a good choice. No argument there. > > Without a doubt, the overhead XML adds over say, something as simple > > as > > CSV is considerable, and XML would appear to be rather more hard to > > work > > with in things like Python and PERL. > > Considerable is an understatement, its literally up to 10 or 20 times > more space and that means bandwidth and CPU resource to > process it. > > Using XML as a storage medium - a file - is not too bad, you suck > it up, process it and foirget the file. MY big gripe is that people > are > inceasingly trying to use XML as the payload in comms systems, > sending XML messages around. This is crazy! The extra cost of the > network and hardware needed to process that kind of architecture > is usually far higher than the minimal savings it gives in developer > time. > [As an example I recently had to uplift the bandwidth of the > intranet pipe in one of our buildings from 4Mb to a full ATM pipe > of 34Mb just to accomodate a system 'upgrade' that now used XML. > That raised the network operations cost of that one building > from $10k per year to over $100k! - The software upgrade by > contrast was only a one-off cost of $10K] This is an example of the resource balancing act that computer people have been faced with since the beginning. The most scarce/expensive resource dictates the program's/system's design. In Alan's example high speed bandwidth is the limiting resource. A data transmission method that fails to minimize use of that resource is therefore a bad solution. Python itself is a result of this balancing act. Interpreted languages like Basic were invented to overcome the disadvantages of writing of programs in machine-readable, human-unfriendly formats. Compiled languages like C were invented to overcome the slow execution speed of interpreted programs. As processor speeds increased and execution times dropped , interpreted languages like Python once again became viable for large scale programs. > > So, I think XML has it's place but I will not fault anyone for > > trying to > > make it easier to get code to work. > > Absolutely agree with that. Just be careful how you use it and > think of the real cost impact you may be having if its your choice. > Your customers will thank you. So here's my off-topic question: Ajax is being touted as the 'best-known method' (BKM) for
Re: [Tutor] XML: Expletive Deleted (OT)
Carroll, Barry wrote: > So here's my off-topic question: Ajax is being touted as the 'best-known > method' (BKM) for making dynamic browser-based applications, and XML is > the BKM for transferring data in Ajax land. If XML is a bad idea for > network data-transfer, what medium should be used instead? JSON is a popular alternative to XML for Ajax applications. It is much lighter-weight than XML and easier to parse in JavaScript. http://json.org/ Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python related mags
Hello, Andrew: > -Original Message- > Date: Mon, 12 Jun 2006 07:53:05 -0400 > From: Andrew Robert <[EMAIL PROTECTED]> > Subject: [Tutor] Python related mags > To: Python Tutor > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=ISO-8859-1 > > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Hi everyone, > > Does anyone know of any Python related magazines available that would be > worth subscribing to? > > Ideally, a free one, but I would not object to a reasonably priced one > either. > > I was able to find pyzine located at www.pyzine.com but it appears to be > defunct. Dr. Dobbs puts out a weekly Python related e-zine that be useful to you. I couldn't find the URL, but I get a link to it every week in the Python-announce-list: http://mail.python.org/mailman/listinfo/python-announce-list. HTH. Barry [EMAIL PROTECTED] 541-302-1107 We who cut mere stones must always be envisioning cathedrals. -Quarry worker's creed ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] please remove this address from list: [EMAIL PROTECTED]
you will need to do it yourself.http://mail.python.org/mailman/listinfo/python-listOn 6/12/06, graphic design <[EMAIL PROTECTED]> wrote: not sure how i got on this list. please remove my email address from it. thank you. [EMAIL PROTECTED] ___Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutorsorry,-- Daniel McQuay[EMAIL PROTECTED] boxster.homelinux.orgH: 814.825.0847M: 814-341-6233 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] datetime: What happended yesterday? :-)
I've been looking at datetime and cannot figure out what was a very simple operation with the time module. How does one add or subtract 24 (or any number) of hours from a given date and time using the datetime module? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Mod-python
Hi! I have about 17 lines of text (about system information) that I need to pass to a remote web server AND I've been asked to send this data via Apache. I have to write a python script that will fetch a URL to pass this text. I understand that if I want to use the POST method, I would need to have a page with a submit button, and this is not the case. I also know that with GET, the length of the url is limited. What is the best way to send a long string? Hope anyone can point me to the right direction.. Thanks, Patricia ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Mod-python
Well, POST or PUT are the normal ways to do that. You need to interact with the person running the web server to see how they need it delivered - if they're expecting a GET and you give them a POST, it isn't going to work very well :) Dustin On Jun 12, 2006, at 2:48 PM, patricia wrote: > Hi! > > I have about 17 lines of text (about system information) that I need > to pass to > a remote web server AND I've been asked to send this data via Apache. > I have to > write a python script that will fetch a URL to pass this text. I > understand that > if I want to use the POST method, I would need to have a page with a > submit > button, and this is not the case. I also know that with GET, the > length of the > url is limited. What is the best way to send a long string? > > Hope anyone can point me to the right direction.. > Thanks, > Patricia > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] datetime: What happended yesterday? :-)
doug shawhan wrote: > I've been looking at datetime and cannot figure out what was a very > simple operation with the time module. > > How does one add or subtract 24 (or any number) of hours from a given > date and time using the datetime module? Use a datetime.timedelta: In [1]: import datetime In [2]: now = datetime.datetime.now() In [3]: now Out[3]: datetime.datetime(2006, 6, 12, 16, 7, 47, 69000) In [4]: one_day = datetime.timedelta(hours=24) In [5]: now-one_day Out[5]: datetime.datetime(2006, 6, 11, 16, 7, 47, 69000) Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] datetime: What happended yesterday? :-)
Heh. Your example would look very, very nice in the timedelta (http://docs.python.org/lib/datetime-timedelta.html) section of the docs! :-) It makes perfect sense, the authors probably thought it was too easy to need an explaination ...On 6/12/06, Kent Johnson < [EMAIL PROTECTED]> wrote:doug shawhan wrote:> I've been looking at datetime and cannot figure out what was a very > simple operation with the time module.>> How does one add or subtract 24 (or any number) of hours from a given> date and time using the datetime module?Use a datetime.timedelta: In [1]: import datetimeIn [2]: now = datetime.datetime.now()In [3]: nowOut[3]: datetime.datetime(2006, 6, 12, 16, 7, 47, 69000)In [4]: >In [5]: now-one_day Out[5]: datetime.datetime(2006, 6, 11, 16, 7, 47, 69000)Kent___Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] datetime: What happended yesterday? :-)
doug shawhan wrote: > Heh. Your example would look very, very nice in the timedelta > (http://docs.python.org/lib/datetime-timedelta.html) section of the > docs! :-) > > It makes perfect sense, the authors probably thought it was too easy to > need an explaination ... It is noted in the "Supported operations" for datetime, buried in the middle of this page: http://docs.python.org/lib/datetime-datetime.html Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Mod-python
> > I have about 17 lines of text (about system information) that I need to pass > to > a remote web server AND I've been asked to send this data via Apache. I have > to > write a python script that will fetch a URL to pass this text. I understand > that > if I want to use the POST method, I would need to have a page with a submit > button, and this is not the case. I also know that with GET, the length of the > url is limited. What is the best way to send a long string? When you say you that you want to send this data via Apache do you mean that the web server you are sending to is running Apache or that you are communicating from one server to another? If you simply want to emulate a a web page with a submit button that sends a Post you do it with code a bit like the following import urllib, urllib2 url = "http://www.somesite.com/somefolder/exampl1.cgi"; dict = {} dict["field1"] = "value1" dict["field2"] = "value2" ... dict["fieldn"] = "valuen" urldata = urllib.urlencode(dict) req = urllib2.Request(url) req.add_header('User-agent','Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0') fd = urllib2.urlopen(req,urldata) Regards Peter Jessop > > Hope anyone can point me to the right direction.. > Thanks, > Patricia > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Mod-python
Hi, When you say you that you want to send this data via Apache do youmean that the web server you are sending to is running Apache Yes. If you simply want to emulate a a web page with a submit button thatsends a Post you do it with code a bit like the following import urllib, urllib2url = "" href="http://www.somesite.com/somefolder/exampl1.cgi">http://www.somesite.com/somefolder/exampl1.cgi"dict = {}dict["field1"] = "value1" dict["field2"] = "value2"...dict["fieldn"] = "valuen"urldata = urllib.urlencode(dict)req = urllib2.Request(url)req.add_header('User-agent','Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0')fd = urllib2.urlopen(req,urldata)RegardsPeter Jessop I'll try this out. Thank you! Patricia >> Hope anyone can point me to the right direction..> Thanks, > Patricia>> ___> Tutor maillist - Tutor@python.org> http://mail.python.org/mailman/listinfo/tutor> ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python related mags
On Jun 12, 2006, at 5:53 AM, Andrew Robert wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Hi everyone, > > Does anyone know of any Python related magazines available that would > be > worth subscribing to? > > Ideally, a free one, but I would not object to a reasonably priced one > either. > > I was able to find pyzine located at www.pyzine.com but it appears to > be > defunct. > > I don' think there's much out there. Sometime Linux Journal will have Python related articles, sometimes Dr. Dobbs. As popular as Python is, it's probably not popular enough to sustain a magazine devoted just to it. Mike ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python related mags
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Now that is a real pity. Wish I were talented enough to do it myself. Mike Hansen wrote: > On Jun 12, 2006, at 5:53 AM, Andrew Robert wrote: > >> -BEGIN PGP SIGNED MESSAGE- >> Hash: SHA1 >> >> Hi everyone, >> >> Does anyone know of any Python related magazines available that would >> be >> worth subscribing to? >> >> Ideally, a free one, but I would not object to a reasonably priced one >> either. >> >> I was able to find pyzine located at www.pyzine.com but it appears to >> be >> defunct. >> >> > I don' think there's much out there. Sometime Linux Journal will have > Python related articles, sometimes Dr. Dobbs. As popular as Python is, > it's probably not popular enough to sustain a magazine devoted just to > it. > > Mike > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > - -- Thank you, Andrew Robert Systems Architect Information Technologies MFS Investment Management Phone: 617-954-5882 E-mail: [EMAIL PROTECTED] Linux User Number: #201204 -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.1 (MingW32) Comment: GnuPT 2.7.2 iD8DBQFEjhFTDvn/4H0LjDwRAq14AJ9RzCA4o5pNW6y47c1mM/Tzm0R3EACfZ0ec KxReJbvZERlj2gHx4Y+FB58= =kKr8 -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Wondering is there a pyQT list
johnf wrote: > Hi, > I was wondering if there is a pyqt list like the > [EMAIL PROTECTED] list? > http://mats.imk.fraunhofer.de/mailman/listinfo/pykde ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python related mags
On Mon, 2006-06-12 at 21:13 -0400, Andrew Robert wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Now that is a real pity. > > Wish I were talented enough to do it myself. Someone could do something like Tux Magazine (http://www.tuxmagazine.org/) . Each month they put out a free Linux magazine in the form of a downloadable pdf file. It's supposed to be geared toward new Linux users. I particularly like the pdf format, because it doesn't take up space in my apartment, just on my hard drive... ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python related mags
Andrew Robert wrote: > Does anyone know of any Python related magazines available that would be > worth subscribing to? > Why bother when there are many excellent websites with good python articles? I have found that my consumption of print media has fallen to practically zero not including things I print out myself in the years since I discovered the Internet. The vast majority of python users are on the net. It does not surprise me at all that there are no printed python magazines. It is much more efficient to put it all online. -- Tracy R Reed http://ultraviolet.org ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] [tutor] debug process
Hello, Is there a way to debug (trace) the python code line by line? emily - Поличба 666. Само в кината. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [tutor] debug process
[EMAIL PROTECTED] schrieb: > Hello, > > Is there a way to debug (trace) the python code line by line? > > emily > Hi emily! You can use The Python Debugger or pdb, see: http://www.python.org/doc/2.4.2/lib/module-pdb.html HTH, Wolfram ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor