Re: Convert StringIO to string

2006-10-16 Thread skryskalla
Jonathan Bowlas wrote:
> But obviously replace() isn't an attribute of StringIO so I guess I need to
> convert it to a string first, can someone please advise how I can do this?

StringIO objects are file-like objects, so you need to use read or
readlines to get the string data out of it (just like a regular file).
Before reading remember to seek back to the beginning to get all of the
data ("Be kind, rewind!"):

>>> import StringIO
>>> s = StringIO.StringIO()
>>> s.write("hello world\n")
>>> s.seek(0)
>>> s.read()
'hello world\n'

>>> s = StringIO.StringIO()
>>> s.write("hello world\n")
>>> s.read()
''

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


Re: Generating Cutter numbers

2006-05-20 Thread skryskalla
Gerard Flanagan wrote:
> All
>
> would anyone happen to have code to generate Cutter Numbers:
>
>   eg. http://www1.kfupm.edu.sa/library/cod-web/Cutter-numbers.htm
>
> or is anyone looking for something to do?-)  (I'm under pressure!)
>
> def cutter(lname, fname, book_title):
>

What do you use lname and fname (author first name and last name?) for?
 The page you linked to does not have any information (that I could
see) about first names or last names.

I wrote a script to see if I could capture what the table is doing on
the page you linked to.  It gets the Cutter number right about 50% of
the time, otherwise its off by a few digits.

I am stumped about what to do when the first letter is Q not followed
by U.  It says to use numbers 2-29 for the second letters a-t, but that
is obviously not right (for one thing t would be 21, not 29).

Since you seem a little bit more experienced in library science could
you explain what is going on? :)

you can find the script here:
http://lost-theory.org/python/cutter.txt

 Titlemine  realmatch?
---
IBM  I26I26 True
IdahoI33I33 True
Ilardo   I43I4  False
Import   I47I48 False
InmanI56I56 True
Ipswich  I67I67 True
Ito  I86I87 False
Ivy  I99I94 False
Sadron   S23S23 True
Scanlon  S33S29 False
SchreiberS37S37 True
Shillingburg S55S53 False
Singer   S56S57 False
Stinson  S75S75 True
Suryani  S87S87 True
SymposiumS96S96 True
Qadduri  Q23Q23 True
Qiao Q103   Q27 False
QuadeQ33Q33 True
Queiroz  Q45Q45 True
QuinnQ56Q56 True
Quorum   Q67Q67 True
QutubQ88Q88 True
Qvortrup Q236   Q97 False
Campbell C46C36 False
Ceccaldi C53C43 False
Chertok  C64C48 False
ClarkC73C58 False
Cobblestone  C43C63 False
CryerC79C79 True
Cuellar  C74C84 False
Cymbal   C36C96 False


Steve

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