Re: Stripping sRGB profile from PNGs in python

2015-07-23 Thread Laura Creighton
To scale images, you should get Pillow, which can construct new images based on old ones for arbitrary size. see: http://pillow.readthedocs.org/en/latest/reference/Image.html Pillow is a fork of PIL. PIL isn't being maintained, Pillow is. Note that reading this is a good idea: http://united-code

Re: Stripping sRGB profile from PNGs in python

2015-07-23 Thread Emile van Sebille
On 7/23/2015 10:31 AM, Ryan Holmes wrote: We're getting this error when trying to load some of out projects images: libpng warning: iCCP: known incorrect sRGB profile The source files that we have some with incorrect sRGB profiles. We don't have control over the source files, but what we

Stripping sRGB profile from PNGs in python

2015-07-23 Thread Ryan Holmes
We're getting this error when trying to load some of out projects images: libpng warning: iCCP: known incorrect sRGB profile The source files that we have some with incorrect sRGB profiles. We don't have control over the source files, but what we normally do is take them and scale them d

Re: Stripping unencodable characters from a string

2015-05-08 Thread Serhiy Storchaka
On 05.05.15 21:19, Paul Moore wrote: I want to write a string to an already-open file (sys.stdout, typically). However, I *don't* want encoding errors, and the string could be arbitrary Unicode (in theory). The best way I've found is data = data.encode(file.encoding, errors='replace').dec

Re: Stripping unencodable characters from a string

2015-05-05 Thread Chris Angelico
On Wed, May 6, 2015 at 4:19 AM, Paul Moore wrote: > I want to write a string to an already-open file (sys.stdout, typically). > However, I *don't* want encoding errors, and the string could be arbitrary > Unicode (in theory). The best way I've found is > > data = data.encode(file.encoding,

Re: Stripping unencodable characters from a string

2015-05-05 Thread Marko Rauhamaa
Paul Moore : > Nor can I - that's my point. But if all I have is an open text-mode > file with the "strict" error mode, I have to incur one encode, and I > have to make sure that no characters are passed to that encode which > can't be encoded. The file-like object you are given carries some bag

Re: Stripping unencodable characters from a string

2015-05-05 Thread Jon Ribbens
On 2015-05-05, Paul Moore wrote: > I want to write a string to an already-open file (sys.stdout, > typically). However, I *don't* want encoding errors, and the string > could be arbitrary Unicode (in theory). The best way I've found is > > data = data.encode(file.encoding, errors='replace').de

Re: Stripping unencodable characters from a string

2015-05-05 Thread Paul Moore
On Tuesday, 5 May 2015 20:01:04 UTC+1, Dave Angel wrote: > On 05/05/2015 02:19 PM, Paul Moore wrote: > > You need to specify that you're using Python 3.4 (or whichever) when > starting a new thread. Sorry. 2.6, 2.7, and 3.3+. It's for use in a cross-version library. > If you're going to take c

Re: Stripping unencodable characters from a string

2015-05-05 Thread Dave Angel
On 05/05/2015 02:19 PM, Paul Moore wrote: You need to specify that you're using Python 3.4 (or whichever) when starting a new thread. I want to write a string to an already-open file (sys.stdout, typically). However, I *don't* want encoding errors, and the string could be arbitrary Unicode

Stripping unencodable characters from a string

2015-05-05 Thread Paul Moore
I want to write a string to an already-open file (sys.stdout, typically). However, I *don't* want encoding errors, and the string could be arbitrary Unicode (in theory). The best way I've found is data = data.encode(file.encoding, errors='replace').decode(file.encoding) file.write(data)

Re: Floating point "g" format not stripping trailing zeros

2015-02-14 Thread Ian Kelly
On Fri, Feb 13, 2015 at 6:22 PM, Mark Lawrence wrote: > On 14/02/2015 00:11, Ian Kelly wrote: >> >> On Fri, Feb 13, 2015 at 4:05 PM, Mark Lawrence >> wrote: >>> >>> I still think it's a bug as the 'p' being referred to in the OP's >>> original >>> message is "The precision is a decimal number ind

Re: Floating point "g" format not stripping trailing zeros

2015-02-13 Thread Gregory Ewing
Mark Lawrence wrote: I still think it's a bug as the 'p' being referred to in the OP's original message is "The precision is a decimal number indicating how many digits should be displayed after the decimal point for a floating point value formatted with 'f' and 'F', or before and after the dec

Re: Floating point "g" format not stripping trailing zeros

2015-02-13 Thread Mark Lawrence
On 14/02/2015 00:11, Ian Kelly wrote: On Fri, Feb 13, 2015 at 4:05 PM, Mark Lawrence wrote: I still think it's a bug as the 'p' being referred to in the OP's original message is "The precision is a decimal number indicating how many digits should be displayed after the decimal point for a float

Re: Floating point "g" format not stripping trailing zeros

2015-02-13 Thread Ian Kelly
On Fri, Feb 13, 2015 at 4:05 PM, Mark Lawrence wrote: > I still think it's a bug as the 'p' being referred to in the OP's original > message is "The precision is a decimal number indicating how many digits > should be displayed after the decimal point for a floating point value > formatted with 'f

Re: Floating point "g" format not stripping trailing zeros

2015-02-13 Thread Mark Lawrence
On 12/02/2015 23:46, Ian Kelly wrote: On Thu, Feb 12, 2015 at 1:23 PM, Hrvoje Nikšić wrote: from decimal import Decimal as D x = D(1)/D(999) '{:.15g}'.format(x) '0.00100100100100100' [...] I'd say it's a bug. P is 15, you've got 17 digits after the decimal place and two of those are insign

Re: Floating point "g" format not stripping trailing zeros

2015-02-13 Thread Ian Kelly
On Fri, Feb 13, 2015 at 2:40 PM, Ian Kelly wrote: > On Fri, Feb 13, 2015 at 2:22 PM, Grant Edwards > wrote: >> On 2015-02-13, Dave Angel wrote: >>> On the other hand, the Decimal package has a way that the programmer >>> can tell how many digits to use at each stage of the calculation. >> >> Th

Re: Floating point "g" format not stripping trailing zeros

2015-02-13 Thread Ian Kelly
On Fri, Feb 13, 2015 at 2:22 PM, Grant Edwards wrote: > On 2015-02-13, Dave Angel wrote: >> On the other hand, the Decimal package has a way that the programmer >> can tell how many digits to use at each stage of the calculation. > > That's what surpised me. From TFM: > > https://docs.python.org

Re: Floating point "g" format not stripping trailing zeros

2015-02-13 Thread Grant Edwards
On 2015-02-13, Dave Angel wrote: > On 02/13/2015 03:33 PM, Grant Edwards wrote: >> On 2015-02-13, Ian Kelly wrote: >> >>> Significant digits are within the precision of the calculation. >>> Writing 1.230 indicates that the fourth digit is known to be zero. >>> Writing 1.23 outside a context of ex

Re: Floating point "g" format not stripping trailing zeros

2015-02-13 Thread Dave Angel
On 02/13/2015 03:33 PM, Grant Edwards wrote: On 2015-02-13, Ian Kelly wrote: Significant digits are within the precision of the calculation. Writing 1.230 indicates that the fourth digit is known to be zero. Writing 1.23 outside a context of exact calculation indicates that the fourth digit i

Re: Floating point "g" format not stripping trailing zeros

2015-02-13 Thread Ian Kelly
On Fri, Feb 13, 2015 at 1:33 PM, Grant Edwards wrote: > On 2015-02-13, Ian Kelly wrote: >> On Fri, Feb 13, 2015 at 7:02 AM, Grant Edwards >> wrote: >>> On 2015-02-12, Ian Kelly wrote: On Thu, Feb 12, 2015 at 1:23 PM, Hrvoje Nikšić wrote: > {:.15g} is supposed to give 15 digits o

Re: Floating point "g" format not stripping trailing zeros

2015-02-13 Thread Grant Edwards
On 2015-02-13, Ian Kelly wrote: > On Fri, Feb 13, 2015 at 7:02 AM, Grant Edwards > wrote: >> On 2015-02-12, Ian Kelly wrote: >>> On Thu, Feb 12, 2015 at 1:23 PM, Hrvoje Nikšić wrote: >>> {:.15g} is supposed to give 15 digits of precision, but with trailing zeros removed. >>> >>> The

Re: Floating point "g" format not stripping trailing zeros

2015-02-13 Thread Ian Kelly
On Fri, Feb 13, 2015 at 7:02 AM, Grant Edwards wrote: > On 2015-02-12, Ian Kelly wrote: >> On Thu, Feb 12, 2015 at 1:23 PM, Hrvoje Nikšić wrote: >> >>> {:.15g} is supposed to give 15 digits of precision, but with trailing >>> zeros removed. >> >> The doc says with "insignificant" trailing zeros

Re: Floating point "g" format not stripping trailing zeros

2015-02-13 Thread Ian Kelly
On Fri, Feb 13, 2015 at 2:26 AM, Hrvoje Nikšić wrote: > Ian Kelly writes: >> When you specify the a precision of 15 in your format string, you're >> telling it to take the first 15 of those. It doesn't care that the >> last couple of those are zeros, because as far as it's concerned, >> those digi

Re: Floating point "g" format not stripping trailing zeros

2015-02-13 Thread Grant Edwards
On 2015-02-12, Ian Kelly wrote: > On Thu, Feb 12, 2015 at 1:23 PM, Hrvoje Nikšić wrote: > >> {:.15g} is supposed to give 15 digits of precision, but with trailing >> zeros removed. > > The doc says with "insignificant" trailing zeros removed, not all > trailing zeros. Can somebody explain the di

Re: Floating point "g" format not stripping trailing zeros

2015-02-13 Thread Hrvoje Nikšić
Ian Kelly writes: > When you specify the a precision of 15 in your format string, you're > telling it to take the first 15 of those. It doesn't care that the > last couple of those are zeros, because as far as it's concerned, > those digits are significant. OK, it's a bit surprising, but also cons

Re: Floating point "g" format not stripping trailing zeros

2015-02-12 Thread Ian Kelly
On Thu, Feb 12, 2015 at 1:23 PM, Hrvoje Nikšić wrote: >> > from decimal import Decimal as D >> > x = D(1)/D(999) >> > '{:.15g}'.format(x) >> >> >> >> '0.00100100100100100' > [...] >> > I'd say it's a bug. P is 15, you've got 17 digits after the decimal place >> > and two of those are

Re: Floating point "g" format not stripping trailing zeros

2015-02-12 Thread Hrvoje Nikšić
> > from decimal import Decimal as D > > x = D(1)/D(999) > > '{:.15g}'.format(x) > >> > >> '0.00100100100100100' [...] > > I'd say it's a bug. P is 15, you've got 17 digits after the decimal place > > and two of those are insignificant trailing zeros. > > Actually it's the float versio

Re: Floating point "g" format not stripping trailing zeros

2015-02-11 Thread Ian Kelly
On Wed, Feb 11, 2015 at 3:19 PM, Ian Kelly wrote: > On Wed, Feb 11, 2015 at 2:48 PM, Mark Lawrence > wrote: >> On 11/02/2015 20:02, Hrvoje Nikšić wrote: >>> >>> According to the documentation of the "g" floating-point format, >>> trailing zeros should be stripped from the resulting string: >>> >

Re: Floating point "g" format not stripping trailing zeros

2015-02-11 Thread Ian Kelly
On Wed, Feb 11, 2015 at 2:48 PM, Mark Lawrence wrote: > On 11/02/2015 20:02, Hrvoje Nikšić wrote: >> >> According to the documentation of the "g" floating-point format, >> trailing zeros should be stripped from the resulting string: >> >> """ >> General format. For a given precision p >= 1, this r

Re: Floating point "g" format not stripping trailing zeros

2015-02-11 Thread Mark Lawrence
On 11/02/2015 20:02, Hrvoje Nikšić wrote: According to the documentation of the "g" floating-point format, trailing zeros should be stripped from the resulting string: """ General format. For a given precision p >= 1, this rounds the number to p significant digits and then formats the result in

Floating point "g" format not stripping trailing zeros

2015-02-11 Thread Hrvoje Nikšić
According to the documentation of the "g" floating-point format, trailing zeros should be stripped from the resulting string: """ General format. For a given precision p >= 1, this rounds the number to p significant digits and then formats the result in either fixed-point format or in scientific n

Re: Stripping in Python

2015-01-15 Thread ronnyma
On Thursday, January 15, 2015 at 11:35:11 AM UTC+1, Abdul Abdul wrote: > Hello, > > I have a program where I read a line input from the keyboard. > > If I remove this portion of code after reading the line, I get an error: > > line = line.rstrip() > > Why is that? Sh

Re: Stripping in Python

2015-01-15 Thread Peter Otten
Abdul Abdul wrote: > I have a program where I read a line input from the keyboard. > > If I remove this portion of code after reading the line, I get an error: > > line = line.rstrip() > > Why is that? Should stripping be always be used after reading an input in >

Stripping in Python

2015-01-15 Thread Abdul Abdul
Hello, I have a program where I read a line input from the keyboard. If I remove this portion of code after reading the line, I get an error: line = line.rstrip() Why is that? Should stripping be always be used after reading an input in Python? Thanks. -- https://mail.python.org/mailman

Re: stripping (from item in list)

2014-07-20 Thread Terry Reedy
On 7/20/2014 5:40 AM, Martin S wrote: while c >=0: x=games[c][0] if x=="#": del games[c] #This removes the comments from the file parsed else: games[c].rstrip('\n') #This does nothing, expected to remove \n Chris already pointed out error he

Re: stripping (from item in list)

2014-07-20 Thread Chris Angelico
On Sun, Jul 20, 2014 at 8:06 PM, Martin S wrote: > And yes, definately should be able to build a better parser ... I want > it to work first. Fair enough. That's why I answered your actual question before mentioning that as a tacked-on almost postscript. :) ChrisA -- https://mail.python.org/mai

Re: stripping (from item in list)

2014-07-20 Thread Martin S
Craps should have guessed that was the problem. Must have misunderstood the examples. But thanks =) And yes, definately should be able to build a better parser ... I want it to work first. /Martin S 2014-07-20 11:57 GMT+02:00 Chris Angelico : > On Sun, Jul 20, 2014 at 7:40 PM, Martin S wrote:

Re: stripping (from item in list)

2014-07-20 Thread Chris Angelico
On Sun, Jul 20, 2014 at 7:40 PM, Martin S wrote: > games[c].rstrip('\n') #This does nothing, expected to remove \n > > While all records in the remaining list now are valid, all also still > have "\n" at the end. What did I miss here? Strings don't change. When you call rstrip(), it r

stripping (from item in list)

2014-07-20 Thread Martin S
While preparing to my gui to the app I made I thought it would be nice to be able to parse a text file with results using the same tool. So: I read a result file to a list, and every record gets appended with "\n" ... OK, so I look up how to remove it. And this doesn't work while c >=0: x

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-19 Thread Dave Angel
On 19/9/2013 11:53, Neil Cerutti wrote: > On 2013-09-18, Dave Angel wrote: >> On 18/9/2013 17:40, Neil Hodgson wrote: >> >>> Dave Angel: >>> So is the bug in Excel, in Windows, or in the Python library? Somebody is falling down on the job; if Windows defines the string as ending at >>

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-19 Thread Neil Cerutti
On 2013-09-18, Dave Angel wrote: > On 18/9/2013 17:40, Neil Hodgson wrote: > >> Dave Angel: >> >>> So is the bug in Excel, in Windows, or in the Python library? Somebody >>> is falling down on the job; if Windows defines the string as ending at >>> the first null, then the Python interface shoul

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-19 Thread random832
On Wed, Sep 18, 2013, at 16:13, Dave Angel wrote: > So is the bug in Excel, in Windows, or in the Python library? Somebody > is falling down on the job; if Windows defines the string as ending at > the first null, then the Python interface should use that when defining > the text defined with CF_

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-18 Thread Dave Angel
On 18/9/2013 17:40, Neil Hodgson wrote: > Dave Angel: > >> So is the bug in Excel, in Windows, or in the Python library? Somebody >> is falling down on the job; if Windows defines the string as ending at >> the first null, then the Python interface should use that when defining >> the text defin

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-18 Thread Neil Hodgson
Dave Angel: So is the bug in Excel, in Windows, or in the Python library? Somebody is falling down on the job; if Windows defines the string as ending at the first null, then the Python interface should use that when defining the text defined with CF_UNICODETEXT. Everything is performing

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-18 Thread Dave Angel
On 18/9/2013 15:40, MRAB wrote: > On 18/09/2013 20:28, stephen.bou...@gmail.com wrote: >> Thanks to everyone for their help. Using everyone's suggestions, this seems >> to work: >> >> import win32clipboard, win32con >> >> def getclipboard(): >> win32clipboard.OpenClipboard() >> s = win3

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-18 Thread MRAB
On 18/09/2013 20:28, stephen.bou...@gmail.com wrote: Thanks to everyone for their help. Using everyone's suggestions, this seems to work: import win32clipboard, win32con def getclipboard(): win32clipboard.OpenClipboard() s = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT)

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-18 Thread stephen . boulet
Thanks to everyone for their help. Using everyone's suggestions, this seems to work: import win32clipboard, win32con def getclipboard(): win32clipboard.OpenClipboard() s = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT) win32clipboard.CloseClipboard() if '\0' in s:

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-18 Thread random832
On Fri, Sep 13, 2013, at 12:09, random...@fastmail.us wrote: > Anyway, to match behavior found in other applications when pasting from > the clipboard, I would suggest using: > > if s.contains('\0'): s = s[:s.index('\0')] > > Which will also remove non-null bytes after the first null (but if the

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-17 Thread stephen . boulet
On Thursday, September 12, 2013 6:01:20 PM UTC-5, stephen...@gmail.com wrote: > I have an excel file. When I select cells, copy from excel, and then use > win32clipboard to get the contents of the clipboard, I have a 131071 > character string. > > > > When I save the file as a text file, and u

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-13 Thread random832
On Fri, Sep 13, 2013, at 10:38, stephen.bou...@gmail.com wrote: > > Hm, that gives me a "Type str doesn't support the buffer API" message. > > Aha, I need to use str(s, encoding='utf8').rstrip('\0'). It's not a solution to your problem, but why aren't you using CF_UNICODETEXT, particularly if you

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-13 Thread Neil Cerutti
On 2013-09-13, stephen.bou...@gmail.com wrote: > On Thursday, September 12, 2013 10:43:46 PM UTC-5, Neil Hodgson wrote: >> Stephen Boulet: >> >> >> >> > From the clipboard contents copied from the spreadsheet, the characters >> > s[:80684] were the visible cell contents, and s[80684:] all sta

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-13 Thread stephen . boulet
On Friday, September 13, 2013 9:31:45 AM UTC-5, stephen...@gmail.com wrote: > On Thursday, September 12, 2013 10:43:46 PM UTC-5, Neil Hodgson wrote: > > > Stephen Boulet: > > > > > > > > > > > > > From the clipboard contents copied from the spreadsheet, the characters > > > s[:80684] were

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-13 Thread stephen . boulet
On Thursday, September 12, 2013 10:43:46 PM UTC-5, Neil Hodgson wrote: > Stephen Boulet: > > > > > From the clipboard contents copied from the spreadsheet, the characters > > s[:80684] were the visible cell contents, and s[80684:] all started with > > "b'\x0" and lack any useful info for what

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-12 Thread Neil Hodgson
Stephen Boulet: From the clipboard contents copied from the spreadsheet, the characters s[:80684] were the visible cell contents, and s[80684:] all started with "b'\x0" and lack any useful info for what I'm trying to accomplish. Looks like Excel is rounding up its clipboard allocation to

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-12 Thread MRAB
On 13/09/2013 01:58, stephen.bou...@gmail.com wrote: Hi Steven. Here is my code: import win32clipboard, win32con def getclipboard(): win32clipboard.OpenClipboard() s = win32clipboard.GetClipboardData(win32con.CF_TEXT) win32clipboard.CloseClipboard() return s I use this help

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-12 Thread stephen . boulet
Hi Steven. Here is my code: import win32clipboard, win32con def getclipboard(): win32clipboard.OpenClipboard() s = win32clipboard.GetClipboardData(win32con.CF_TEXT) win32clipboard.CloseClipboard() return s I use this helper function to grab the text on the clipboard and do useful

Re: Stripping characters from windows clipboard with win32clipboard from excel

2013-09-12 Thread Steven D'Aprano
On Thu, 12 Sep 2013 16:01:20 -0700, stephen.boulet wrote: > I have an excel file. When I select cells, copy from excel, and then use > win32clipboard to get the contents of the clipboard, I have a 131071 > character string. How exactly are you using win32clipboard, and what exact result are you

Stripping characters from windows clipboard with win32clipboard from excel

2013-09-12 Thread stephen . boulet
I have an excel file. When I select cells, copy from excel, and then use win32clipboard to get the contents of the clipboard, I have a 131071 character string. When I save the file as a text file, and use the python 3.3 open command to read its contents, I only have 80684 characters. Excel (an

Benchmarking stripping of Unicode characters which are invalid XML

2012-03-18 Thread Alex Willmer
Last week I was surprised to discover that there are Unicode characters that aren't valid in an XML document. That is regardless of escaping (e.g. �) and unicode encoding (e.g. UTF-8) - not every Unicode string can be stored in XML. The valid characters are (as of XML 1.0) #x9 | #xA | #xD | [#x2

Re: stripping fields from xml file into a csv

2010-02-28 Thread Stefan Behnel
Hal Styli, 01.03.2010 00:15: > Stefan, I was happy to see such concise code. > Your python worked with only very minor modifications. > > Hai's test xml data *without* the first and last line is close enough > to the data I am using: > > > > > > > > ... quirky. > > I get a large file given

Re: stripping fields from xml file into a csv

2010-02-28 Thread Hal Styli
On 28 Feb, 19:20, Stefan Behnel wrote: > Hai Vu, 28.02.2010 17:41: > > > By the way, Stefan, I am using Python 2.6. Do you know the differences > > between ElementTree and cElementTree? > > Use cElementTree, it's implemented in C and a lot faster and more memory > friendly. > > http://effbot.org/z

Re: stripping fields from xml file into a csv

2010-02-28 Thread Stefan Behnel
Hai Vu, 28.02.2010 17:41: > By the way, Stefan, I am using Python 2.6. Do you know the differences > between ElementTree and cElementTree? Use cElementTree, it's implemented in C and a lot faster and more memory friendly. http://effbot.org/zone/celementtree.htm#benchmarks http://codespeak.net/lxm

Re: stripping fields from xml file into a csv

2010-02-28 Thread Hai Vu
On Feb 28, 12:05 am, Stefan Behnel wrote: > Hal Styli, 27.02.2010 21:50: > > > I have a sed solution to the problems below but would like to rewrite > > in python... > > Note that sed (or any other line based or text based tool) is not a > sensible way to handle XML. If you want to read XML, use a

Re: stripping fields from xml file into a csv

2010-02-28 Thread Roland Mueller
2010/2/28 Stefan Behnel > Roland Mueller, 28.02.2010 13:01: > > The stylesheet is test.xsl and the insput data test.xml. The following > > Python code the applies the stylesheet on the input data and puts the > output > > into foo. > > > > Python code: > > #!/usr/bin/python > > import sys > > imp

Re: stripping fields from xml file into a csv

2010-02-28 Thread Stefan Behnel
Roland Mueller, 28.02.2010 13:01: > The stylesheet is test.xsl and the insput data test.xml. The following > Python code the applies the stylesheet on the input data and puts the output > into foo. > > Python code: > #!/usr/bin/python > import sys > import libxml2 > import libxslt > > styledoc =

Re: stripping fields from xml file into a csv

2010-02-28 Thread Roland Mueller
Hello, 2010/2/28 Stefan Behnel > Hal Styli, 27.02.2010 21:50: > > I have a sed solution to the problems below but would like to rewrite > > in python... > > Note that sed (or any other line based or text based tool) is not a > sensible way to handle XML. If you want to read XML, use an XML parse

Re: stripping fields from xml file into a csv

2010-02-28 Thread Stefan Behnel
Hal Styli, 27.02.2010 21:50: > I have a sed solution to the problems below but would like to rewrite > in python... Note that sed (or any other line based or text based tool) is not a sensible way to handle XML. If you want to read XML, use an XML parser. They are designed to do exactly what you w

Re: stripping fields from xml file into a csv

2010-02-27 Thread Hai Vu
On Feb 27, 12:50 pm, Hal Styli wrote: > Hello, > > Can someone please help. > I have a sed solution to the problems below but would like to rewrite > in python... > > I need to strip out some data from a quirky xml file into a csv: > > from something like this > > < . cust="dick" product=

Re: stripping fields from xml file into a csv

2010-02-27 Thread Zaphod
On Sat, 27 Feb 2010 12:50:38 -0800, Hal Styli wrote: > Hello, > > Can someone please help. > I have a sed solution to the problems below but would like to rewrite in > python... > > I need to strip out some data from a quirky xml file into a csv: > > from something like this > > < . cust="

Re: stripping fields from xml file into a csv

2010-02-27 Thread John Bokma
Hal Styli writes: > Hello, > > Can someone please help. > I have a sed solution to the problems below but would like to rewrite > in python... > > I need to strip out some data from a quirky xml file into a csv: > > from something like this > > < . cust="dick" product="eggs" ... quantity

stripping fields from xml file into a csv

2010-02-27 Thread Hal Styli
Hello, Can someone please help. I have a sed solution to the problems below but would like to rewrite in python... I need to strip out some data from a quirky xml file into a csv: from something like this < . cust="dick" product="eggs" ... quantity="12" > < cust="tom" pr

Re: Stripping non-numbers from a file parse without nested lists?

2009-04-01 Thread daku9999
On Apr 1, 8:10 am, jay logan wrote: > On Apr 1, 11:05 am, jay logan wrote: > > > > > On Apr 1, 2:35 am, daku9...@gmail.com wrote: > > > > On Mar 31, 6:47 pm, "Rhodri James" > > > wrote: > > > > > What you're doing (pace error checking) seems fine for the data > > > > structures that you're using

Re: Stripping non-numbers from a file parse without nested lists?

2009-04-01 Thread jay logan
On Apr 1, 11:05 am, jay logan wrote: > On Apr 1, 2:35 am, daku9...@gmail.com wrote: > > > > > On Mar 31, 6:47 pm, "Rhodri James" > > wrote: > > > > What you're doing (pace error checking) seems fine for the data > > > structures that you're using.  I'm not entirely clear what your usage > > > pat

Re: Stripping non-numbers from a file parse without nested lists?

2009-04-01 Thread jay logan
On Apr 1, 2:35 am, daku9...@gmail.com wrote: > On Mar 31, 6:47 pm, "Rhodri James" > wrote: > > > What you're doing (pace error checking) seems fine for the data > > structures that you're using.  I'm not entirely clear what your usage > > pattern for "dip" and "dir" is once you've got them, so I c

Re: Stripping non-numbers from a file parse without nested lists?

2009-04-01 Thread Lorenzo
Maybe you can try a regex, something like -- import re pattern = re.compile('^(\d+)/(\d+).*') def read_data(filename): fh = open(filename, "r", encoding="ascii") for line in fh: if pattern.match(line): dip_,dir_ = pattern.match(line).groups()

Re: Stripping non-numbers from a file parse without nested lists?

2009-03-31 Thread daku9999
On Mar 31, 6:47 pm, "Rhodri James" wrote: > What you're doing (pace error checking) seems fine for the data > structures that you're using.  I'm not entirely clear what your usage > pattern for "dip" and "dir" is once you've got them, so I can't say > whether there's a more appropriate shape for

Re: Stripping non-numbers from a file parse without nested lists?

2009-03-31 Thread andrew cooke
gt;> dip/dir. >> (some more lines of garbage) >> 55/158 >> (some more lines of garbage) >> 33/156 >> etc. >> >> and I'm stripping out the 55/158 values (with error checking >> removed): >> -- >> def read_data(fil

Re: Stripping non-numbers from a file parse without nested lists?

2009-03-31 Thread Rhodri James
e) 33/156 etc. and I'm stripping out the 55/158 values (with error checking removed): -- def read_data(filename): fh = open(filename, "r", encoding="ascii") for line in fh: for word in line.lower().split(): if &qu

Stripping non-numbers from a file parse without nested lists?

2009-03-30 Thread daku9999
There has got to be a better way of doing this: I'm reading in a file that has a lot of garbage, but eventually has something that looks similar to: (some lines of garbage) dip/dir. (some more lines of garbage) 55/158 (some more lines of garbage) 33/156 etc. and I'm stripping out

Re: Stripping parts of a path

2008-07-27 Thread Tim Cook
On Sun, 2008-07-27 at 04:32 +, Tim Roberts wrote: > This doesn't do what you think it does. The parameter to rstrip is a set: > as long as the last character is in the set 'abcdhiloprs/', it will remove > it and check the next one. All of the characters in "shop" are in that > set. Thanks

Re: Stripping parts of a path

2008-07-26 Thread Tim Roberts
Tim Cook <[EMAIL PROTECTED]> wrote: > >I just ran into an issue with the rstrip method when using it on path >strings. > >When executing a function I have a need to strip off a portion of the >current working directory and add on a path to a log file. Initially >this worked great but then I added

Re: Stripping parts of a path

2008-07-26 Thread Dan Stromberg
On Sat, 26 Jul 2008 08:59:15 -0300, Tim Cook wrote: > Hi All, > > I just ran into an issue with the rstrip method when using it on path > strings. > > When executing a function I have a need to strip off a portion of the > current working directory and add on a path to a log file. Initially > t

Re: Stripping parts of a path

2008-07-26 Thread Larry Bates
hings don't work. Help on built-in function rstrip: rstrip(...) S.rstrip([chars]) -> string or unicode Return a copy of the string S with trailing whitespace removed. If chars is given and not None, remove characters in chars instead. If chars is unicode, S will be converted to uni

Re: Stripping parts of a path

2008-07-26 Thread Karen Tracey
ot;The chars argument is not a suffix; rather, all combinations of its values are stripped" Thus, since the characters p,o,h, and s are all in the argument you supplied to rstrip, they are removed, then stripping is stopped at the k because that is not in the chars arg you supplied. To do what you really want I think you need to use rfind/rindex to locate the last occurrence of the substring and then truncate the string yourself. Karen -- http://mail.python.org/mailman/listinfo/python-list

Stripping parts of a path

2008-07-26 Thread Tim Cook
Hi All, I just ran into an issue with the rstrip method when using it on path strings. When executing a function I have a need to strip off a portion of the current working directory and add on a path to a log file. Initially this worked great but then I added a branch in SVN which caused the pa

Re: [Regexes] Stripping puctuation from a text

2008-05-23 Thread Andrew Lee
shabda raaj wrote: I want to strip punctuation from text. So I am trying, p = re.compile('[a-zA-Z0-9]+') p.sub('', 'I love tomatoes!! hell yeah! ... Why?') ' !! ! ... ?' Which gave me all the chars which I want to replace. So Next I tried by negating the regex, p = re.compile('^[a-zA-Z0

[Regexes] Stripping puctuation from a text

2008-05-22 Thread shabda raaj
I want to strip punctuation from text. So I am trying, >>> p = re.compile('[a-zA-Z0-9]+') >>> p.sub('', 'I love tomatoes!! hell yeah! ... Why?') ' !! ! ... ?' Which gave me all the chars which I want to replace. So Next I tried by negating the regex, >>> p = re.compile('^[a-zA-Z0-9]+') >>> p

Re: Stripping scripts from HTML with regular expressions

2008-04-11 Thread Stefan Behnel
Michel Bouwmans wrote: > I don't think HTMLParser was doing anything wrong here. I needed to parse a > HTML document, but it contained script-blocks with document.write's in > them. I only care for the content outside these blocks but HTMLParser will > choke on such a block when it isn't encapsulat

RE: Stripping scripts from HTML with regular expressions

2008-04-10 Thread Michel Bouwmans
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Reedick, Andrew wrote: >> -Original Message- >> From: [EMAIL PROTECTED] [mailto:python- >> [EMAIL PROTECTED] On Behalf Of Michel Bouwmans >> Sent: Wednesday, April 09, 2008 5:44 PM >> To: python-list@python

RE: Stripping scripts from HTML with regular expressions

2008-04-10 Thread Reedick, Andrew
> -Original Message- > From: [EMAIL PROTECTED] [mailto:python- > [EMAIL PROTECTED] On Behalf Of Michel Bouwmans > Sent: Wednesday, April 09, 2008 5:44 PM > To: python-list@python.org > Subject: RE: Stripping scripts from HTML with regular expressions > > >

Re: Stripping scripts from HTML with regular expressions

2008-04-10 Thread Paul McGuire
; > greetz > MFB This pyparsing-based HTML stripper (http://pyparsing.wikispaces.com/ space/showimage/htmlStripper.py) strips *all* HTML tags, scripts, and comments. To pare down to just stripping scripts, just change this line: firstPass = (htmlComment | scriptBody

Re: Stripping scripts from HTML with regular expressions

2008-04-10 Thread Nikita the Spider
PM > > To: python-list@python.org > > Subject: Stripping scripts from HTML with regular expressions > > > > Hey everyone, > > > > I'm trying to strip all script-blocks from a HTML-file using regex. > > > > [Insert obligatory comment abo

RE: Stripping scripts from HTML with regular expressions

2008-04-09 Thread Michel Bouwmans
Reedick, Andrew wrote: > > >> -Original Message- >> From: [EMAIL PROTECTED] [mailto:python- >> [EMAIL PROTECTED] On Behalf Of Michel Bouwmans >> Sent: Wednesday, April 09, 2008 3:38 PM >> To: python-list@python.org >> Subject: Stripping

RE: Stripping scripts from HTML with regular expressions

2008-04-09 Thread Reedick, Andrew
> -Original Message- > From: [EMAIL PROTECTED] [mailto:python- > [EMAIL PROTECTED] On Behalf Of Michel Bouwmans > Sent: Wednesday, April 09, 2008 3:38 PM > To: python-list@python.org > Subject: Stripping scripts from HTML with regular expressions > > Hey ever

Re: Stripping scripts from HTML with regular expressions

2008-04-09 Thread Stefan Behnel
Michel Bouwmans wrote: > I'm trying to strip all script-blocks from a HTML-file using regex. You might want to take a look at lxml.html instead, which comes with an HTML cleaner module: http://codespeak.net/lxml/lxmlhtml.html#cleaning-up-html Stefan -- http://mail.python.org/mailman/listinfo/py

RE: Stripping scripts from HTML with regular expressions

2008-04-09 Thread Reedick, Andrew
> -Original Message- > From: [EMAIL PROTECTED] [mailto:python- > [EMAIL PROTECTED] On Behalf Of Michel Bouwmans > Sent: Wednesday, April 09, 2008 3:38 PM > To: python-list@python.org > Subject: Stripping scripts from HTML with regular expressions > > Hey ever

Stripping scripts from HTML with regular expressions

2008-04-09 Thread Michel Bouwmans
Hey everyone, I'm trying to strip all script-blocks from a HTML-file using regex. I tried the following in Python: testfile = open('testfile') testhtml = testfile.read() regex = re.compile(']*>(.*?)', re.DOTALL) result = regex.sub('', blaat) print result This strips far more away then just the

RE: Stripping whitespace

2008-01-24 Thread Reedick, Andrew
> -Original Message- > From: [EMAIL PROTECTED] [mailto:python- > [EMAIL PROTECTED] On Behalf Of John Machin > Sent: Wednesday, January 23, 2008 5:48 PM > To: python-list@python.org > Subject: Re: Stripping whitespace > > On Jan 24, 7:57 am, "Reedick, Andr

Re: Stripping whitespace

2008-01-24 Thread cokofreedom
On Jan 24, 8:21 am, ryan k <[EMAIL PROTECTED]> wrote: > On Jan 23, 6:30 pm, John Machin <[EMAIL PROTECTED]> wrote: > > > On Jan 24, 9:50 am, ryan k <[EMAIL PROTECTED]> wrote: > > > > Steven D'Aprano, you are a prick. > > > And your reasons for coming to that stridently expressed conclusion > > afte

Re: Stripping whitespace

2008-01-23 Thread ryan k
On Jan 23, 6:30 pm, John Machin <[EMAIL PROTECTED]> wrote: > On Jan 24, 9:50 am, ryan k <[EMAIL PROTECTED]> wrote: > > > Steven D'Aprano, you are a prick. > > And your reasons for coming to that stridently expressed conclusion > after reading a posting that was *not* addressed to you are .? Be

  1   2   >