Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 02-14-2010, 10:09 AM   #1
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Help a beginner:Python/Recipe Unicode and ASCII

I'm writing a recipe and am having trouble with unicode formatting. I want to create an image tag (imgtag) using Beautiful Soup, and I've pulled a non-image tag (<photopath>) from another page that has the url I need as its contents, but it's stored as unicode u'http://....jpg'.

I've converted the contents of imgtag to a string using str() to define the src="http://....jpg" part of the imgtag, but that converted string is in the form: [u'http://....jpg'].

When I use that string as the src of the img tag, I get:
src="[u'http://....jpg']" instead of src="http://....jpg"

I'm reduced to taking a slice of the string [3:-2] to rip off the "[u'" part at the front, and the "']" at the end. Clearly, I'm bad at strings, but can anyone tell me how to handle this better?

I'm starting with a BeautifulSoup tag <photopath> from
soup2.find('photopath') that has the http://...jpg string as its NavigableString contents and I want to use that string as the imgsrc string in a Tag as:

imgtag = Tag(soup, 'img', [('src', imgsrc)])

without resorting to converting to a str and taking a slice to chop part of it out. The content is already a string, so surely there is an easier/cleaner way to do that. What am I missing?

Thanks.
Starson17 is offline   Reply With Quote
Old 02-14-2010, 11:21 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 36,791
Karma: 16422043
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
unicode(soup2.find('photopath').string)
kovidgoyal is online now   Reply With Quote
Advert
Old 02-15-2010, 11:10 AM   #3
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by kovidgoyal View Post
unicode(soup2.find('photopath').string)
Thanks.
Starson17 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
weird ascii character p3aul Calibre 7 10-14-2009 05:10 PM
Python Unicode Demystified ahi Workshop 2 09-18-2009 12:45 PM
fictions for a beginner? mgph Reading Recommendations 18 06-14-2009 04:09 AM
Converting non-ascii/non-unicode text - pictures the way to go? politicorific Workshop 5 04-02-2009 05:59 AM
Ascii file ProDigit Lounge 1 12-25-2008 10:08 PM


All times are GMT -4. The time now is 09:57 PM.


MobileRead.com is a privately owned, operated and funded community.