[Tutor] please unsubscribe me
itpro4470 at hushmail.com
itpro4470 at hushmail.com
Fri Mar 9 05:44:34 CET 2007
On Thu, 08 Mar 2007 03:00:15 -0800 tutor-request at python.org wrote:
>Send Tutor mailing list submissions to
> tutor at 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
> tutor-request at python.org
>
>You can reach the person managing the list at
> tutor-owner at python.org
>
>When replying, please edit your Subject line so it is more
>specific
>than "Re: Contents of Tutor digest..."
>
>
>Today's Topics:
>
> 1. Re: help:find a string in a text and replace it with a
> anotherstring (Mike Hansen)
> 2. Re: Tutor Digest, Vol 37, Issue 22 (Steve Maguire)
> 3. Passing a list, dict or tuple to MySQLdb? (Alan Wardroper)
> 4. Re: Passing a list, dict or tuple to MySQLdb? (Bill
>Campbell)
> 5. ssl error when trying to connect to https (also using
> timeoutsocket.py) (Tsila Hassine)
> 6. about __std__ zip file (Glenfiddich apayart)
> 7. Re: Roman Numeral to Digital (Kent Johnson)
>
>
>-------------------------------------------------------------------
>---
>
>Message: 1
>Date: Wed, 7 Mar 2007 10:42:54 -0700
>From: "Mike Hansen" <Mike.Hansen at atmel.com>
>Subject: Re: [Tutor] help:find a string in a text and replace it
>with
> a anotherstring
>To: <tutor at python.org>
>Message-ID:
> <57B026980605A64F9B23484C5659E32E637BF7 at poccso.US.ad.atmel.com>
>Content-Type: text/plain; charset="us-ascii"
>
>
>
>> -----Original Message-----
>> From: tutor-bounces at python.org
>> [mailto:tutor-bounces at python.org] On Behalf Of mastjeptor regli
>> Sent: Wednesday, March 07, 2007 10:34 AM
>> To: tutor at python.org
>> Subject: [Tutor] help:find a string in a text and replace it
>> with a anotherstring
>>
>> Hi,folks.
>> At first ,I have a question that I want to ask for
>> help,it is how can I search a specific string in a text (such
>> a in a word document) and replace it with another string?
>> Second,if the text is changed dynamicly,can I use a
>> variable string(has been assigned a string) to search in the
>> text and replace it with another variable string.for example,
>> Regex Substitution: s/email/e-mail ,if the string of "email"
>> and "e-mail" are both changed from time to time,can we apply
>> variable string (which has been assigned a value of string
>> type) instead of constant string of "email" and "e-mail" to
>> construct a regex substitution expression ?
>> Please reply with experience in using regular
>> expression or python library functions to find and replace a
>> string in a text to help me. Thank you for your attention.
>>
>
>You might not need regular expressions. You can use replace
>method.
>
>In [11]: x = "Bozo"
>
>In [12]: z = "Bozo The Clown"
>
>In [13]: y = "Krusty"
>
>In [14]: z.replace(x,y)
>Out[14]: 'Krusty The Clown'
>
>You could probably populate a dictionary of the words you want to
>replace and their replacements. Then use the replace method on the
>strings.
>
>Note that Word documents are binary gibberish, so you'd need to
>use
>win32 python windows stuff making this more complicated. On plain
>text
>files, it wouldn't be too bad.
>
>Mike
>
>
>------------------------------
>
>Message: 2
>Date: Wed, 7 Mar 2007 12:37:42 -0600
>From: "Steve Maguire" <steve at maguire-family.net>
>Subject: Re: [Tutor] Tutor Digest, Vol 37, Issue 22
>To: tutor at python.org
>Message-ID:
> <cadaed980703071037t39ee07a9td3b065230295b988 at mail.gmail.com>
>Content-Type: text/plain; charset="iso-8859-1"
>
>>
>>
>> ---------- Forwarded message ----------
>> From: Tim Golden <mail at timgolden.me.uk>
>> To:
>> Date: Wed, 07 Mar 2007 15:48:20 +0000
>> Subject: Re: [Tutor] Printing labels
>> Steve Maguire wrote:
>> > I am a Python beginner. For my first task I wanted to fix a
>program
>> that I
>> > originally wrote in Excel with VBA. I want to create a mySQL
>database
>> > holding my DVD collection, edit it in Python, and print labels
>for the
>> > cases
>> > with an index for filing and a catalog of all the titles their
>indices.
>> >
>> > To print the labels the way I want, I will need extended
>control over
>> the
>> > printer: positioning the printer precisely and changing
>fonts, colors,
>> and
>> > background colors. Is there a public python library that
>could give me
>> > this
>> > level of control?
>>
>> Best bet is probably using Reportlab (http://reportlab.org) to
>generate
>> PDF. Their platypus layout scheme is very flexible, and you may
>even
>> find someone's already done labels as an example.
>>
>> TJG
>>
>>
>Thanks Tim. I'll check that out right away.
>Steve
>-------------- next part --------------
>An HTML attachment was scrubbed...
>URL:
>http://mail.python.org/pipermail/tutor/attachments/20070307/188e407
>8/attachment-0001.html
>
>------------------------------
>
>Message: 3
>Date: Wed, 07 Mar 2007 15:55:53 -0800
>From: Alan Wardroper <python at wardroper.org>
>Subject: [Tutor] Passing a list, dict or tuple to MySQLdb?
>To: tutor at python.org
>Message-ID: <45EF5109.3000909 at wardroper.org>
>Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
>I'm parsing some data to feed to a MySQL database, and would like
>to be
>able to pass in a list (a dictionary or a series of tuples) in the
>cursor.execute() or cursor.executemany() statement, but everything
>I've
>tried raises errors. I'm sure it's a matter of correct formatting
>the
>list as a sequence...
>
>CODE:
>import sys, MySQLdb
>conn = MySQLdb.connect (host = "localhost", user = "user", psswd =
>"xxxx" db = "testdb")
>cursor = conn.cursor()
>
>infile = open(sys.argv[2], 'r')
>list_of_tuples = []
>for line in infile:
> tuple = (line.split()[0], line.split()[1])
> list_of_tuples.append(tuple)
>
>cursor.executemany("UPDATE LOW_PRIORITY sometable SET field1 = %s
>WHERE
>field2 = %s", (list_of_tuples)
>
>"""
>example data:
>ID123445 somestring1
>ID223445 somestring2
>ID323445 somestring3
>ID423445 somestring4
>ID523445 somestring5
>"""
>
>Naively, I thought this would result in an execute statement like:
>cursor.executemany("UPDATE LOW_PRIORITY sometable SET field1 = %s
>WHERE
>field2 = %s", ('ID123445', 'somestring1'), ('ID223445',
>'somestring2'),
>('ID323445', 'somestring3'), ('ID423445', 'somestring4'),
>('ID523445',
>'somestring5'))
>
>But what I get are bunch of errors, last of which is:
>TypeError: not ll arguments converted during string formatting
>
>Or pass in a list of values to use in a SELECT...WHERE...IN (list)
>statement:
>
>ids_to_include = ['ID123445', 'ID223445', 'ID323445']
>cursor.execute("UPDATE sometable SET field1 = 'some standard
>value'
>WHERE field2 IN (%s)", (ids_to_include))
>
>
>I also tried another similar thing, where I tried to pass in the
>name of
>one of the fields as a dictionary key with the value as the
>corresponding value, but it also didn't work--it looked like the
>key was
>bounded in quotes before passing to MySQL, so the db didn't
>recognise
>the fieldname:
>
>for key in dict.keys():
> cursor.execute("INSERT INTO sometable (%s) values (%s)", (key,
>dict[key]))
>
>
>Any pointers?
>
>Thanks
>
>
>
>------------------------------
>
>Message: 4
>Date: Wed, 7 Mar 2007 16:05:27 -0800
>From: Bill Campbell <bill at celestial.net>
>Subject: Re: [Tutor] Passing a list, dict or tuple to MySQLdb?
>To: tutor at python.org
>Message-ID: <20070308000527.GA19529 at ayn.mi.celestial.com>
>Content-Type: text/plain; charset=us-ascii
>
>On Wed, Mar 07, 2007, Alan Wardroper wrote:
>>I'm parsing some data to feed to a MySQL database, and would like
>to be
>>able to pass in a list (a dictionary or a series of tuples) in
>the
>>cursor.execute() or cursor.executemany() statement, but
>everything I've
>>tried raises errors. I'm sure it's a matter of correct
>formatting the
>>list as a sequence...
>>
>>CODE:
>>import sys, MySQLdb
>>conn = MySQLdb.connect (host = "localhost", user = "user", psswd
>=
>>"xxxx" db = "testdb")
>>cursor = conn.cursor()
>>
>>infile = open(sys.argv[2], 'r')
>>list_of_tuples = []
>>for line in infile:
>> tuple = (line.split()[0], line.split()[1])
>> list_of_tuples.append(tuple)
>>
>>cursor.executemany("UPDATE LOW_PRIORITY sometable SET field1 = %s
>WHERE
>>field2 = %s", (list_of_tuples)
>
>I think what you want is ...(*list_of_tuples) similar to the
>syntax used
>when calling functions with position arguments from a list.
>
>Bill
>--
>INTERNET: bill at Celestial.COM Bill Campbell; Celestial Software
>LLC
>URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
>FAX: (206) 232-9186 Mercer Island, WA 98040-0820;
>(206) 236-1676
>
>Few skills are so well rewarded as the ability to convince
>parasites that
>they are victims. -- Thomas Sowell
>
>
>------------------------------
>
>Message: 5
>Date: Thu, 8 Mar 2007 01:47:21 +0100
>From: "Tsila Hassine" <tsila.hassine at gmail.com>
>Subject: [Tutor] ssl error when trying to connect to https (also
>using
> timeoutsocket.py)
>To: tutor at python.org
>Message-ID:
> <da5291e90703071647p2bb9ec6bx392edc2e44d0b9b7 at mail.gmail.com>
>Content-Type: text/plain; charset="iso-8859-1"
>
>Hello all,
>
>in my code i am importing timeoutsocket in order to set the time
>out of a
>connection. When i try to acces an https site I get the error:
>
>"TypeError: ssl() argument 1 must be _socket.socket, not
>_socketobject"
>
>when I am not using the timeoutsocket module, I don't have any
>problems. how
>can i solve this ? (I still need to be able to set the timeout of
>a
>connection...)
>
>thanks,
>Tsila
>-------------- next part --------------
>An HTML attachment was scrubbed...
>URL:
>http://mail.python.org/pipermail/tutor/attachments/20070308/7f9fd01
>d/attachment.htm
>
>------------------------------
>
>Message: 6
>Date: Thu, 8 Mar 2007 01:40:38 -0800 (PST)
>From: Glenfiddich apayart <glen20web at yahoo.com.ph>
>Subject: [Tutor] about __std__ zip file
>To: tutor at python.org
>Message-ID: <792981.89099.qm at web56610.mail.re3.yahoo.com>
>Content-Type: text/plain; charset="utf-8"
>
>hi,
>
>This is my first day and first time i knew about python. i know
>now how to handle the python GUI. i just have a small question
>about the __std zip file. i've read about it on danny website.
>this is the link .Where should i extract the file?
>
>im thinking if i would put it on my Lib folder.. hoping for your
>reply. thanks!
>
>brgds,
>glen20web
>
>
>---------------------------------
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://ph.mail.yahoo.com
>-------------- next part --------------
>An HTML attachment was scrubbed...
>URL:
>http://mail.python.org/pipermail/tutor/attachments/20070308/ed2a062
>f/attachment.html
>
>------------------------------
>
>Message: 7
>Date: Thu, 08 Mar 2007 05:58:31 -0500
>From: Kent Johnson <kent37 at tds.net>
>Subject: Re: [Tutor] Roman Numeral to Digital
>To: Alan Gilfoy <agilfoy at frontiernet.net>, tutor-python
> <tutor at python.org>
>Message-ID: <45EFEC57.4000803 at tds.net>
>Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
>Hi Alan,
>
>I am forwarding your question to tutor at python.org which is the
>correct
>address for the list. tutor-owner at python.org sends questions to
>the
>*maintainers* of the list, not the list itself.
>
>Kent
>
>Alan Gilfoy wrote:
>> I am learning how to program in python as a major component of
>my
>> school's senior project, and my most recent assignment was to
>write a
>> program that converts Roman numerals to digital (base-10 Arabic
>numerals).
>>
>> Now, I was told I have to write the program myself, but I was
>told I was
>> allowed to ask for hints. :)
>>
>> As of right now, I've written a user interface (after all, here
>that's a
>> simple loop-and-prompt setup leading to print statements), but I
>have
>> "dummy code" in the place where the conversion code needs to be.
>>
>> I want to create two separate functions:
>>
>> def.toRoman(digital_input)
>> print "Digital - to - Roman conversion (dummy code)"
>> roman_result = "XXX"
>> return roman_result
>>
>> def.toDigital(roman_input)
>> print "Roman - to - digital conversion (dummy code)"
>> digital_result = 30
>> return digital_result
>>
>> I'm going to set each of those two "inputs" by a prompt asking
>for what
>> the program user wants to work with.
>>
>> #Such as:
>> digital_input = int(raw_input("What digital (base-10) number do
>you wish
>> to convert to Roman numerals?))
>>
>> I'm not sure how I would program Python to run the actual
>conversions.
>>
>> PS: I'm familiar with Roman numerals, and I know how to do the
>> conversions manually.
>>
>>
>>
>>
>>
>>
>
>
>
>------------------------------
>
>_______________________________________________
>Tutor maillist - Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>End of Tutor Digest, Vol 37, Issue 23
>*************************************
Click to consolidate debt and lower month expenses
http://tagline.hushmail.com/fc/CAaCXv1QPxYsLwAs4lrOzOWlcGo2zh0g/
More information about the Tutor
mailing list