Re: python math problem

2013-02-15 Thread John Machin
On Feb 16, 6:39 am, Kene Meniru wrote: > x = (math.sin(math.radians(angle)) * length) > y = (math.cos(math.radians(angle)) * length) A suggestion about coding style: from math import sin, cos, radians # etc etc x = sin(radians(angle)) * length y = cos(radians(angle)) * length ... easier to wri

Re: unicode by default

2011-05-12 Thread John Machin
On Thu, May 12, 2011 4:31 pm, harrismh777 wrote: > > So, the UTF-16 UTF-32 is INTERNAL only, for Python NO. See one of my previous messages. UTF-16 and UTF-32, like UTF-8 are encodings for the EXTERNAL representation of Unicode characters in byte streams. > I also was not aware that UTF-8 chars

Re: unicode by default

2011-05-11 Thread John Machin
On Thu, May 12, 2011 2:14 pm, Benjamin Kaplan wrote: > > If the file you're writing to doesn't specify an encoding, Python will > default to locale.getdefaultencoding(), No such attribute. Perhaps you mean locale.getpreferredencoding() -- http://mail.python.org/mailman/listinfo/python-list

Re: unicode by default

2011-05-11 Thread John Machin
On Thu, May 12, 2011 1:44 pm, harrismh777 wrote: > By > default it looks like Python3 is writing output with UTF-8 as default... > and I thought that by default Python3 was using either UTF-16 or UTF-32. > So, I'm confused here... also, I used the character sequence \u00A3 > which I thought was UT

Re: unicode by default

2011-05-11 Thread John Machin
On Thu, May 12, 2011 11:22 am, harrismh777 wrote: > John Machin wrote: >> (1) You cannot work without using bytes sequences. Files are byte >> sequences. Web communication is in bytes. You need to (know / assume / >> be >> able to extract / guess) the input encodi

Re: urllib2 request with binary file as payload

2011-05-11 Thread John Machin
On Thu, May 12, 2011 10:20 am, Michiel Sikma wrote: > Hi there, > I made a small script implementing a part of Youtube's API that allows > you to upload videos. It's pretty straightforward and uses urllib2. > The script was written for Python 2.6, but the server I'm going to use > it on only has 2.

Re: unicode by default

2011-05-11 Thread John Machin
On Thu, May 12, 2011 8:51 am, harrismh777 wrote: > Is it true that if I am > working without using bytes sequences that I will not need to care about > the encoding anyway, unless of course I need to specify a unicode code > point? Quite the contrary. (1) You cannot work without using bytes seque

codecs.open() doesn't handle platform-specific line terminator

2011-05-09 Thread John Machin
According to the 3.2 docs (http://docs.python.org/py3k/library/codecs.html#codecs.open), """Files are always opened in binary mode, even if no binary mode was specified. This is done to avoid data loss due to encodings using 8-bit values. This means that no automatic conversion of b'\n' is done on

Re: codec for UTF-8 with BOM

2011-05-02 Thread John Machin
On Monday, 2 May 2011 19:47:45 UTC+10, Chris Rebert wrote: > On Mon, May 2, 2011 at 1:34 AM, Ulrich Eckhardt > wrote: > The correct name, as you found below and as is corroborated by the > webpage, seems to be "utf_8_sig": > >>> u"FOøbar".encode('utf_8_sig') > '\xef\xbb\xbfFO\xc3\xb8bar' To com

Re: Snowball to Python compiler

2011-04-21 Thread John Machin
On Friday, April 22, 2011 8:05:37 AM UTC+10, Matt Chaput wrote: > I'm looking for some code that will take a Snowball program and compile > it into a Python script. Or, less ideally, a Snowball interpreter > written in Python. > > (http://snowball.tartarus.org/) If anyone has done such things

Re: getting text out of an xml string

2011-03-05 Thread John Machin
On Mar 5, 8:57 am, JT wrote: > On Mar 4, 9:30 pm, John Machin wrote: > > > Your data has been FUABARred (the first A being for Almost) -- the > > "\u3c00" and "\u3e00" were once "<" and ">" respectively. You will > > Hi John

Re: getting text out of an xml string

2011-03-04 Thread John Machin
On Mar 5, 6:53 am, JT wrote: > Yo, > >  So I have almost convinced a small program to do what I want it to > do.  One thing remains (at least, one thing I know of at the moment): > I am converting xml to some other format, and there are strings in the > xml like this. > > The python: > > elif v ==

Re: py3k: converting int to bytes

2011-02-24 Thread John Machin
On Feb 25, 4:39 am, Terry Reedy wrote: > Note: an as yet undocumented feature of bytes (at least in Py3) is that > bytes(count) == bytes()*count == b'\x00'*count. Python 3.1.3 docs for bytes() say same constructor args as for bytearray(); this says about the source parameter: """If it is an integ

Re: 2to3 chokes on bad character

2011-02-24 Thread John Machin
On Feb 25, 12:00 am, Peter Otten <__pete...@web.de> wrote: > John Machin wrote: > > Your Python 2.x code should be TESTED before you poke 2to3 at it. In > > this case just trying to run or import the offending code file would > > have given an informative syntax error

Re: 2to3 chokes on bad character

2011-02-24 Thread John Machin
On Feb 23, 7:47 pm, "Frank Millman" wrote: > Hi all > > I don't know if this counts as a bug in 2to3.py, but when I ran it on my > program directory it crashed, with a traceback but without any indication of > which file caused the problem. > [traceback snipped] > UnicodeDecodeError: 'utf8' codec

Re: python crash problem

2011-02-05 Thread John Machin
On Feb 3, 8:21 am, Terry Reedy wrote: > On 2/2/2011 2:19 PM, Yelena wrote: > . > > When having a problem with a 3rd party module, not part of the stdlib, > you should give a source. >    http://sourceforge.net/projects/dbfpy/ > This appears to be a compiled extension. Nearly always, when Python >

Re: Interesting bug

2011-01-03 Thread John Machin
On Jan 2, 12:22 am, Daniel Fetchinson wrote: > An AI bot is playing a trick on us. Yes, it appears that the mystery is solved: Mark V. Shaney is alive and well and living in Bangalore :-) -- http://mail.python.org/mailman/listinfo/python-list

Re: Modifying an existing excel spreadsheet

2010-12-22 Thread John Machin
On Dec 21, 8:56 am, Ed Keith wrote: > I have a user supplied 'template' Excel spreadsheet. I need to create a new > excel spreadsheet based on the supplied template, with data filled in. > > I found the tools > herehttp://www.python-excel.org/, andhttp://sourceforge.net/projects/pyexcelerator/.

Re: Ensuring symmetry in difflib.SequenceMatcher

2010-11-24 Thread John Machin
On Nov 24, 8:43 pm, Peter Otten <__pete...@web.de> wrote: > John Yeung wrote: > > I'm generally pleased with difflib.SequenceMatcher:  It's probably not > > the best available string matcher out there, but it's in the standard > > library and I've seen worse in the wild.  One thing that kind of > >

Re: Raw Unicode docstring

2010-11-16 Thread John Machin
On Nov 17, 9:34 am, Alexander Kapps wrote: >  >>> ur"Scheißt\nderBär\nim Wald?" Nicht ohne eine Genehmigung von der Umwelt Erhaltung Abteilung. -- http://mail.python.org/mailman/listinfo/python-list

Re: A bug for raw string literals in Py3k?

2010-10-31 Thread John Machin
On Oct 31, 11:23 pm, Yingjie Lan wrote: > > > So I suppose this is a bug? > > > It's not, see > > >http://docs.python.org/py3k/reference/lexical_analysis.html#literals > > > # Specifically, a raw string cannot end in a single backslash > > Thanks! That looks weird to me ... doesn't this contradict

Re: Runtime error

2010-10-29 Thread John Machin
On Oct 29, 3:26 am, Sebastian wrote: > Hi all, > > I am new to python and I don't know how to fix this error. I only try to > execute python (or a cgi script) and I get an ouptu like > > [...] > 'import site' failed; traceback: > Traceback (most recent call last): > File "/usr/lib/python2.6/site.p

Re: Get alternative char name with unicodedata.name() if no formal one defined

2010-10-14 Thread John Machin
On Oct 14, 7:25 pm, Dirk Wallenstein wrote: > Hi, > I'd like to get control char names for the first 32 codepoints, but they > apparently only have an alias and no official name. Is there a way to > get the alternative character name (alias) in Python? > AFAIK there is no programatically-availabl

Re: Wrong default endianess in utf-16 and utf-32 !?

2010-10-12 Thread John Machin
jmfauth gmail.com> writes: > When an endianess is not specified, (BE, LE, unmarked forms), > the Unicode Consortium specifies, the default byte serialization > should be big-endian. > > See http://www.unicode.org/faq//utf_bom.html > Q: Which of the UTFs do I need to support? > and > Q: Why do so

cp936 uses gbk codec, doesn't decode `\x80` as U+20AC EURO SIGN

2010-10-10 Thread John Machin
|>>> '\x80'.decode('cp936') Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 0: incomplete multibyte sequence However: Retrieved 2010-10-10 from http://www.unicode.org/Public /MAPPINGS/VENDORS/MICSFT/WINDOWS/CP936.TXT

strange results from sys.version

2010-09-27 Thread John Machin
I am trying to help a user of my xlrd package who says he is getting anomalous results on his "work computer" but not on his "home computer". Attempts to reproduce his alleged problem in a verifiable manner on his "work computer" have failed, so far ... the only meaning difference in script ou

Re: Detect string has non-ASCII chars without checking each char?

2010-08-22 Thread John Machin
On Aug 23, 1:10 am, "Michel Claveau - MVP" wrote: > Re ! > > > Try your code with u"abcd\xa1" ... it says it's ASCII. > > Ah?  in my computer, it say "False" Perhaps your computer has a problem. Mine does this with both Python 2.7 and Python 2.3 (which introduced the unicodedata.normalize function

Re: Detect string has non-ASCII chars without checking each char?

2010-08-22 Thread John Machin
On Aug 22, 5:07 pm, "Michel Claveau - MVP" wrote: > Hi! > > Another way : > >   # -*- coding: utf-8 -*- > >   import unicodedata > >   def test_ascii(struni): >       strasc=unicodedata.normalize('NFD', struni).encode('ascii','replace') >       if len(struni)==len(strasc): >          return True >

Re: re.sub and variables

2010-08-12 Thread John Machin
On Aug 13, 7:33 am, fuglyducky wrote: > On Aug 12, 2:06 pm, fuglyducky wrote: > > > > > I have a function that I am attempting to call from another file. I am > > attempting to replace a string using re.sub with another string. The > > problem is that the second string is a variable. When I get t

Re: Ascii to Unicode.

2010-07-30 Thread John Machin
On Jul 30, 4:18 am, Carey Tilden wrote: > In this case, you've been able to determine the > correct encoding (latin-1) for those errant bytes, so the file itself > is thus known to be in that encoding. The most probably "correct" encoding is, as already stated, and agreed by the OP to be, cp1252.

Re: Ascii to Unicode.

2010-07-28 Thread John Machin
On Jul 29, 4:32 am, "Joe Goldthwaite" wrote: > Hi, > > I've got an Ascii file with some latin characters. Specifically \xe1 and > \xfc.  I'm trying to import it into a Postgresql database that's running in > Unicode mode. The Unicode converter chokes on those two characters. > > I could just manua

Re: Where is the help page for re.MatchObject?

2010-07-28 Thread John Machin
On Jul 28, 1:26 pm, Peng Yu wrote: > I know the library reference webpage for re.MatchObject is > athttp://docs.python.org/library/re.html#re.MatchObject > > But I don't find such a help page in python help(). Does anybody know > how to get it in help()? Yes, but it doesn't tell you very much:

Re: newb

2010-07-27 Thread John Machin
On Jul 27, 9:07 pm, whitey wrote: > hi all. am totally new to python and was wondering if there are any > newsgroups that are there specifically for beginners. i have bought a > book for $2 called "learn to program using python" by alan gauld. > starting to read it but it was written in 2001. pres

Re: Unicode error

2010-07-24 Thread John Machin
dirknbr gmail.com> writes: > I have kind of developped this but obviously it's not nice, any better > ideas? > > try: > text=texts[i] > text=text.encode('latin-1') > text=text.encode('utf-8') > except: > text=' ' As Steven has poin

Re: Python 2.7 released

2010-07-04 Thread John Machin
On Jul 5, 12:27 pm, Martineau wrote: > On Jul 4, 8:34 am, Benjamin Peterson wrote: > > > > > On behalf of the Python development team, I'm jocund to announce the second > > release candidate of Python 2.7. > > > Python 2.7 will be the last major version in the 2.x series. However, it > > will >

Re: SyntaxError not honoured in list comprehension?

2010-07-04 Thread John Machin
On Jul 5, 1:08 am, Thomas Jollans wrote: > On 07/04/2010 03:49 PM, jmfauth wrote: > >   File "", line 1 > >     print9.0 > >            ^ > > SyntaxError: invalid syntax > > somewhat strange, yes. There are two tokens, "print9" (a name) and ".0" (a float constant) -- looks like SyntaxError to me.

Re: escape character / csv module

2010-07-02 Thread John Machin
On Jul 2, 6:04 am, MRAB wrote: > The csv module imports from _csv, which suggests to me that there's code > written in C which thinks that the "\x00" is a NUL terminator, so it's a > bug, although it's very unusual to want to write characters like "\x00" > to a CSV file, and I wouldn't be surpri

Re: Handling text lines from files with some (few) starnge chars

2010-06-05 Thread John Machin
On Jun 6, 12:14 pm, MRAB wrote: > Paulo da Silva wrote: > > Em 06-06-2010 00:41, Chris Rebert escreveu: > >> On Sat, Jun 5, 2010 at 4:03 PM, Paulo da Silva > >> wrote: > > ... > > >> Specify the encoding of the text when opening the file using the > >> `encoding` parameter. For Windows-1252 for e

Re: signed vs unsigned int

2010-06-02 Thread John Machin
On Jun 2, 4:43 pm, johnty wrote: > i'm reading bytes from a serial port, and storing it into an array. > > each byte represents a signed 8-bit int. > > currently, the code i'm looking at converts them to an unsigned int by > doing ord(array[i]). however, what i'd like is to get the _signed_ > inte

Re: expat parsing error

2010-06-01 Thread John Machin
On Jun 2, 1:57 am, "kak...@gmail.com" wrote: > On Jun 1, 11:12 am, "kak...@gmail.com" wrote: > > > > > On Jun 1, 11:09 am, John Bokma wrote: > > > > "kak...@gmail.com" writes: > > > > On Jun 1, 10:34 am, Stefan Behnel wrote: > > > >> kak...@gmail.com, 01.06.2010 16:00: > > > > >> > how can i f

Re: Help with Regexp, \b

2010-05-31 Thread John Machin
On May 30, 1:30 am, andrew cooke wrote: > > That's what I thought it did...  Then I read the docs and confused > "empty string" with "space"(!) and convinced myself otherwise.  I > think I am going senile. Not necessarily. Conflating concepts like "string containing whitespace", "string containi

Re: UnicodeDecodeError having fetch web page

2010-05-26 Thread John Machin
Rob Williscroft rtw.me.uk> writes: > > Barry wrote in news:83dc485a-5a20-403b-99ee-c8c627bdbab3 > @m21g2000vbr.googlegroups.com in gmane.comp.python.general: > > > UnicodeDecodeError: 'utf8' codec can't decode byte 0x8b in position 1: > > unexpected code byte > > It may not be you, en.wiktion

Re: help need to write a python spell checker

2010-05-18 Thread John Machin
On May 19, 1:37 pm, Steven D'Aprano wrote: > On Wed, 19 May 2010 13:01:10 +1000, Nigel Rowe wrote: > > I'm happy to do you homework for you, cost is us$1000 per hour.  Email > > to your professor automatically on receipt. > > I'll do it for $700 an hour! he could save the money if he oogledgay or

Re: Puzzled by code pages

2010-05-15 Thread John Machin
Adam Tauno Williams whitemice.org> writes: > On Fri, 2010-05-14 at 20:27 -0400, Adam Tauno Williams wrote: > > I'm trying to process OpenStep plist files in Python. I have a parser > > which works, but only for strict ASCII. However plist files may contain > > accented characters - equivalent t

Re: Fastest way to calculate leading whitespace

2010-05-09 Thread John Machin
dasacc22 gmail.com> writes: > > U presume entirely to much. I have a preprocessor that normalizes > documents while performing other more complex operations. Theres > nothing buggy about what im doing Are you sure? Your "solution" calculates (the number of leading whitespace characters) + (th

Re: How to get xml.etree.ElementTree not bomb on invalid characters in XML file ?

2010-05-04 Thread John Machin
On May 5, 3:43 am, Terry Reedy wrote: > On 5/4/2010 11:37 AM, Stefan Behnel wrote: > > > Barak, Ron, 04.05.2010 16:11: > >> The XML file seems to be valid XML (all XML viewers I tried were able > >> to read it). > >  From Internet Explorer: > > The XML page cannot be displayed > Cannot view XML in

Re: How to get xml.etree.ElementTree not bomb on invalid characters in XML file ?

2010-05-04 Thread John Machin
On May 5, 12:11 am, "Barak, Ron" wrote: > > -Original Message- > > From: Stefan Behnel [mailto:stefan...@behnel.de] > > Sent: Tuesday, May 04, 2010 10:24 AM > > To: python-l...@python.org > > Subject: Re: How to get xml.etree.ElementTree not bomb on > > invalid characters in XML file ? > >

Re: condition and True or False

2010-05-02 Thread John Machin
On May 3, 9:14 am, Steven D'Aprano wrote: > If it is any arbitrary object, then "x and True or False" is just an > obfuscated way of writing "bool(x)". Perhaps their code predates the > introduction of bools, and they have defined global constants True and > False but not bool. Then they removed

Re: csv.py sucks for Decimal

2010-04-25 Thread John Machin
On Apr 23, 9:23 am, Phlip wrote: > When I use the CSV library, with QUOTE_NONNUMERIC, and when I pass in > a Decimal() object, I must convert it to a string. Why must you? What unwanted effect do you observe when you don't convert it? > the search for an alternate CSV module, without > this bug

Re: subtraction is giving me a syntax error

2010-03-15 Thread John Machin
On Mar 16, 5:43 am, Baptiste Carvello wrote: > Joel Pendery a écrit : > > So I am trying to write a bit of code and a simple numerical > > subtraction > > > y_diff = y_diff-H > > > is giving me the error > > > Syntaxerror: Non-ASCII character '\x96' in file on line 70, but no > > encoding declare

Re: datelib pythonification

2010-02-21 Thread John Machin
On Feb 21, 12:37 pm, alex goretoy wrote: > hello all, >     since I posted this last time, I've added a new function dates_diff and [SNIP] I'm rather unsure of the context of this posting ... I'm assuming that the subject "datelib pythonification" refers to trying to make "datelib" more "pythoni

Re: parsing an Excel formula with the re module

2010-01-14 Thread John Machin
On Jan 15, 3:41 pm, Paul McGuire wrote: > I never represented that this parser would handle any and all Excel > formulas! >  But I should hope the basic structure of a pyparsing > solution might help the OP add some of the other features you cited, > if necessary. It's actually pretty common to ta

Re: parsing an Excel formula with the re module

2010-01-14 Thread John Machin
On Jan 14, 2:05 pm, "Gabriel Genellina" wrote: > En Wed, 13 Jan 2010 05:15:52 -0300, Paul McGuire   > escribió: > > >> vsoler wrote: > >> > Hence, I need toparseExcel formulas. Can I do it by means only of re > >> > (regular expressions)? > > > This might give the OP a running start: > > > from p

Re: parsing an Excel formula with the re module

2010-01-14 Thread John Machin
On Jan 13, 7:15 pm, Paul McGuire wrote: > On Jan 5, 1:49 pm, Tim Chase wrote: > > > > > vsoler wrote: > > > Hence, I need toparseExcel formulas. Can I do it by means only of re > > > (regular expressions)? > > > > I know that for simple formulas such as "=3*A7+5" it is indeed > > > possible. What

Re: parsing an Excel formula with the re module

2010-01-12 Thread John Machin
On 12/01/2010 6:26 PM, Chris Withers wrote: John Machin wrote: The xlwt package (of which I am the maintainer) has a lexer and parser for a largish subset of the syntax ... see http://pypi.python.org/pypi/xlwt xlrd, no? A facility in xlrd to decompile Excel formula bytecode into a text

Re: What is built-in method sub

2010-01-11 Thread John Machin
On Jan 12, 7:30 am, Jeremy wrote: > On Jan 11, 1:15 pm, "Diez B. Roggisch" wrote: > > > > > Jeremy schrieb: > > > > On Jan 11, 12:54 pm, Carl Banks wrote: > > >> On Jan 11, 11:20 am, Jeremy wrote: > > > >>> I just profiled one of my Python scripts and discovered that >99% of > > >>> the time wa

Re: Porblem with xlutils/xlrd/xlwt

2010-01-10 Thread John Machin
On Jan 10, 8:51 pm, pp wrote: > On Jan 9, 8:23 am, John Machin wrote: > > > > > On Jan 9, 9:56 pm, pp wrote: > > > > On Jan 9, 3:52 am, Jon Clements wrote: > > > > > On Jan 9, 10:44 am, pp wrote: > > > > > > On Jan 9, 3:42 am, J

Re: Porblem with xlutils/xlrd/xlwt

2010-01-09 Thread John Machin
On Jan 9, 9:56 pm, pp wrote: > On Jan 9, 3:52 am, Jon Clements wrote: > > > > > On Jan 9, 10:44 am, pp wrote: > > > > On Jan 9, 3:42 am, Jon Clements wrote: > > > > > On Jan 9, 10:24 am, pp wrote: > > > yeah all my versions are latest fromhttp://www.python-excel.org. > > > just checked!! How

Re: How to get many places of pi from Machin's Equation?

2010-01-09 Thread John Machin
On Jan 9, 10:31 pm, "Richard D. Moores" wrote: > Machin's Equation is > > 4 arctan (1/5) - arctan(1/239) = pi/4 > > Using Python 3.1 and the math module: > > > > >>> from math import atan, pi > >>> pi > 3.141592653589793 > >>> (4*atan(.2) - atan(1/239))*4 > 3.1415926535897936 > >>> (4*atan(.2) - a

Re: How do I access what's in this module?

2010-01-07 Thread John Machin
On Jan 8, 2:45 pm, Fencer wrote: > On 2010-01-08 04:40, John Machin wrote: > > > > >> For example: > >>   >>>  from lxml.etree import ElementTree > >>   >>>  ElementTree.dump(None) > >> Traceback (most recent call last): > &g

Re: How do I access what's in this module?

2010-01-07 Thread John Machin
On Jan 8, 12:21 pm, Fencer wrote: > Hello, look at this lxml documentation > page:http://codespeak.net/lxml/api/index.html That's for getting details about an object once you know what object you need to use to do what. In the meantime, consider reading the tutorial and executing some of the exa

Re: Astronomy--Programs to Compute Siderial Time?

2010-01-07 Thread John Machin
On Jan 7, 2:40 pm, "W. eWatson" wrote: > John Machin wrote: > > > What you have been reading is the "Internal maintenance > > specification" (large font, near the top of the page) for the module. > > The xml file is the source of the docs, not meant

Re: TypeError

2010-01-06 Thread John Machin
On Jan 7, 1:38 pm, Steve Holden wrote: > John Machin wrote: > > [...]> I note that in the code shown there are examples of building an SQL > > query where the table name is concocted at runtime via the % > > operator ... key phrases: "bad database design"

Re: Astronomy--Programs to Compute Siderial Time?

2010-01-06 Thread John Machin
On Jan 7, 11:40 am, "W. eWatson" wrote: > W. eWatson wrote: > > Is there a smallish Python library of basic astronomical functions? > > There are a number of large such libraries that are crammed with > > excessive functions not needed for common calculations. > > It looks like I've entered a new

Re: TypeError

2010-01-06 Thread John Machin
On Jan 7, 11:14 am, John Machin wrote: > On Jan 7, 3:29 am, MRAB wrote: > > > Victor Subervi wrote: > > > ValueError: unsupported format character '(' (0x28) at index 54 > > >       args = ("unsupported format character '(' (0x28) at i

Re: parsing an Excel formula with the re module

2010-01-06 Thread John Machin
On Jan 6, 6:54 am, vsoler wrote: > On 5 ene, 20:21, vsoler wrote: > > > > > On 5 ene, 20:05, Mensanator wrote: > > > > On Jan 5, 12:35 pm, MRAB wrote: > > > > > vsoler wrote: > > > > > Hello, > > > > > > I am acessing an Excel file by means of Win 32 COM technology. > > > > > For a given cell,

Re: 3 byte network ordered int, How To ?

2010-01-06 Thread John Machin
On Jan 7, 5:33 am, Matthew Barnett wrote: > mudit tuli wrote: > > For a single byte, struct.pack(') > > For two bytes, struct.pack(') > > what if I want three bytes ? > > Four bytes and then discard the most-significant byte: > > struct.pack(')[ : -1] AARRGGHH! network ordering is BIGendian, stru

Re: TypeError

2010-01-06 Thread John Machin
On Jan 7, 3:29 am, MRAB wrote: > Victor Subervi wrote: > > ValueError: unsupported format character '(' (0x28) at index 54 > >       args = ("unsupported format character '(' (0x28) at index 54",) > > > Apparently that character is a "file separator", which I presume is an > > invisible character

Re: Significant whitespace

2010-01-03 Thread John Machin
On Jan 2, 10:29 am, Roy Smith wrote: > > To address your question more directly, here's a couple of ways Fortran > treated whitespace which would surprise the current crop of > Java/PHP/Python/Ruby programmers: > > 1) Line numbers (i.e. the things you could GOTO to) were in column 2-7 > (column 1

Re: creating ZIP files on the cheap

2009-12-23 Thread John Machin
On Dec 24, 7:34 am, samwyse wrote: > I've got an app that's creating Open Office docs; if you don't know, > these are actually ZIP files with a different extension.  In my case, > like many other people, I generating from boilerplate, so only one > component (content.xml) of my ZIP file will ever

Re: dictionary with tuple keys

2009-12-15 Thread John Machin
Ben Finney benfinney.id.au> writes: > In this case, I'll use ‘itertools.groupby’ to make a new sequence of > keys and values, and then extract the keys and values actually wanted. Ah, yes, Zawinski revisited ... itertools.groupby is the new regex :-) > Certainly it might be clearer if written

Re: parse a string of parameters and values

2009-12-12 Thread John Machin
Steven D'Aprano REMOVE-THIS-cybersource.com.au> writes: > > On Sat, 12 Dec 2009 16:16:32 -0800, bsneddon wrote: > > > > I am going to read a text file that is an export from a control system. > > It has lines with information like > > > > base=1 name="first one" color=blue > > > > I would l

Re: Request for py program to insert space between two characters and saved as text?

2009-12-08 Thread John Machin
On Dec 8, 9:42 pm, steve wrote: > On 12/08/2009 02:19 PM, John Machin wrote: > > >> [...snip...] > > Perhaps there are some subtleties of which we are unaware ... > > > I would be very surprised if the OP could not find on a forum much > > closer to home m

Re: Request for py program to insert space between two characters and saved as text?

2009-12-08 Thread John Machin
On Dec 8, 6:56 pm, Dennis Lee Bieber wrote: > On Tue, 8 Dec 2009 08:26:58 +0530, 74yrs old > declaimed the following in gmane.comp.python.general: > > > For Kannada project .txt(not .doc) is used, my requirement is to have one > > space between two characters in Notepad file.  In MSword there is

Re: Why Can't I Delete a File I Created with Win XP?

2009-12-07 Thread John Machin
On Dec 5, 9:57 pm, "W. eWatson" wrote: [snip] >          s = self.current_path s referred to something ... >          s = "Analysis" but now s refers to "Analysis" ... at best, there is redundant & confusing code; at worst, the source of your problem. >          s = os.path.join("Analysis",s) and

Re: Why Can't I Delete a File I Created with Win XP?

2009-12-05 Thread John Machin
On Dec 6, 2:46 am, "W. eWatson" wrote: [snip] >          f = file( s, "wb" ) >          if not f: >              self.LogError( "File creation error 1" ) >              return False Either you are shadowing the built-in function file() or you haven't tested this code ... file() aka open() retur

Re: Filling in a tuple from unknown size list

2009-11-30 Thread John Machin
On Nov 27, 11:18 pm, boblatest wrote: > Hello all, > > (sorry for posting from Google. I currently don't have access to my > normal nntp account.) > > Here's my question: Given a list of onknown length, I'd like to be > able to do the following: > > (a, b, c, d, e, f) = list > > If the list has fe

Re: Feature request: String-inferred names

2009-11-26 Thread John Machin
On Nov 27, 10:43 am, The Music Guy wrote: [snip] > Nonetheless, the fact remains that the feature I'm proposing closely > resembles one that has already been rejected... Well, it's been a few > years since then. Maybe its about time for another PEP to be proposed? Judging by the response you've

Re: Newsgroup for beginners

2009-11-24 Thread John Machin
On Nov 17, 2:56 pm, Grant Edwards wrote: > On 2009-11-17, Paul Rubin wrote: > > > mrholtsr writes: > >> Is there a Python newsgroup for those who are strictly beginners at > >> programming and python? > > > This group has its grouchy moments > > You've really got to try pretty hard to create one

Re: My own accounting python euler problem

2009-11-11 Thread John Machin
On Nov 8, 8:39 am, vsoler wrote: > In the accounting department I am working for we are from time to time > confronted to the following problem: > > A customer sends us a check for a given amount, but without specifying > what invoices it cancels. It is up to us to find out which ones the > paymen

Re: My own accounting python euler problem

2009-11-10 Thread John Machin
On Nov 8, 8:39 am, vsoler wrote: > In the accounting department I am working for we are from time to time > confronted to the following problem: [snip] > My second question is: > 2. this time there are also credit notes outstanding, that is, > invoices with negative amounts. For example,  I=[500,

Re: elementtree XML() unicode

2009-11-05 Thread John Machin
On Nov 5, 12:35 am, Stefan Behnel wrote: > John Machin, 04.11.2009 02:56: > > > On Nov 4, 12:14 pm, Kee Nethery wrote: > >> The reason I am confused is that getResponse2 is classified as an   > >> "str" in the Komodo IDE. I want to make sure I don't lo

Re: elementtree XML() unicode

2009-11-03 Thread John Machin
On Nov 4, 1:06 pm, Kee Nethery wrote: > On Nov 3, 2009, at 5:27 PM, John Machin wrote: > > > > > On Nov 4, 11:01 am, Kee Nethery wrote: > >> Why is this not working and what do I need to do to use Elementtree > >> with unicode? > > > What you need to

Re: elementtree XML() unicode

2009-11-03 Thread John Machin
On Nov 4, 11:01 am, Kee Nethery wrote: > Having an issue with elementtree XML() in python 2.6.4. > > This code works fine: > >       from xml.etree import ElementTree as et >       getResponse = u'''   > bobblehead city>city''' >       theResponseXml = et.XML(getResponse) > > This code errors out

Re: elementtree XML() unicode

2009-11-03 Thread John Machin
On Nov 4, 12:14 pm, Kee Nethery wrote: > On Nov 3, 2009, at 4:44 PM, Gabriel Genellina wrote: > > > En Tue, 03 Nov 2009 21:01:46 -0300, Kee Nethery   > > escribió: > > >> I've removed all the stuff in my code and tried to distill it down   > >> to just what is failing. Hopefully I have not remove

Re: '11' + '1' is '111'?

2009-10-29 Thread John Machin
On Oct 30, 11:52 am, Benjamin Kaplan wrote: > On Thu, Oct 29, 2009 at 8:43 PM, metal wrote: > > '11' + '1' == '111' is well known. > > > but it suprises me '11'+'1' IS '111'. > > > Why? Obviously they are two differnt object. > > > Is this special feature of imutable object? > > It's an implement

Re: Python2.6 + win32com crashes with unicode bug

2009-10-29 Thread John Machin
On Oct 30, 11:11 am, Terry Reedy wrote: > GerritM wrote: [snip] > >   File "C:\Python26\lib\site-packages\win32com\client\build.py", line > > 542, in > >     return filter( lambda char: char in valid_identifier_chars, className) > > UnicodeDecodeError: 'ascii' codec can't decode byte 0x83 in posi

Re: Another (simple) unicode question

2009-10-29 Thread John Machin
On Oct 29, 10:02 pm, Rustom Mody wrote: > Constructhttp://construct.wikispaces.com/is a kick-ass binary file > structurer (written by a 21 year old!) > I thought of trying to port it to python3 but it barfs on some unicode > related stuff (after running 2to3) which I am unable to wrap my head > ar

Re: Bug(s) in Python 3.1.1 Windows installation

2009-10-28 Thread John Machin
On Oct 29, 11:06 am, "Alf P. Steinbach" wrote: > (3) Tkinter not bundled, misleading & incomplete documentation. > > With the file associations in place (the installer managed to do that) running > console programs works fine. > > However, running Tkinter based programs does *not* work: > > > imp

Re: Bug(s) in Python 3.1.1 Windows installation

2009-10-28 Thread John Machin
On Oct 29, 11:56 am, "Alf P. Steinbach" wrote: > Summarizing the main differences 2.6 -> 3.1.1 that I know of so far: print is > now a function (nice), "/" now always produces float result (unsure about > that, > it must surely break a lot or even most of existing code?), xrange() has been > remo

Re: unicode and dbf files

2009-10-27 Thread John Machin
On Oct 28, 2:51 am, Ethan Furman wrote: > John Machin wrote: > > On Oct 27, 7:15 am, Ethan Furman wrote: > > >>Let me rephrase -- say I get a dbf file with an LDID of \x0f that maps > >>to a cp437, and the file came from a german oem machine... could that > &

Re: unicode and dbf files

2009-10-26 Thread John Machin
On Oct 27, 7:15 am, Ethan Furman wrote: > John Machin wrote: > > On Oct 27, 3:22 am, Ethan Furman wrote: > > >>John Machin wrote: > > >>>Try this: > >>>http://webhelp.esri.com/arcpad/8.0/referenceguide/ > > >>Wow.  Question, though:

Re: unicode and dbf files

2009-10-26 Thread John Machin
On Oct 27, 3:22 am, Ethan Furman wrote: > John Machin wrote: > > On Oct 24, 4:14 am, Ethan Furman wrote: > > >>John Machin wrote: > > >>>On Oct 23, 3:03 pm, Ethan Furman wrote: > > >>>>John Machin wrote: > > >>&

Re: python3 Unicode is slow

2009-10-25 Thread John Machin
On Oct 25, 11:12 pm, Dale Gerdemann wrote: > I've written simple code in 2.6 and 3.0 to read every charcter of a > set of files and print out some information for each of these > characters. I tested each program on a large Cyrillic/Latin text. The > result was that the 2.6 version was about 5x fa

Re: unicode and dbf files

2009-10-24 Thread John Machin
On Oct 24, 4:14 am, Ethan Furman wrote: > John Machin wrote: > > On Oct 23, 3:03 pm, Ethan Furman wrote: > > >>John Machin wrote: > > >>>On Oct 23, 7:28 am, Ethan Furman wrote: > > >>>>Greetings, all! > > >>>>I would like t

Re: unicode and dbf files

2009-10-23 Thread John Machin
On Oct 23, 3:03 pm, Ethan Furman wrote: > John Machin wrote: > > On Oct 23, 7:28 am, Ethan Furman wrote: > > >>Greetings, all! > > >>I would like to add unicode support to my dbf project.  The dbf header > >>has a one-byte field to hold the encoding o

Re: unicode and dbf files

2009-10-22 Thread John Machin
On Oct 23, 7:28 am, Ethan Furman wrote: > Greetings, all! > > I would like to add unicode support to my dbf project.  The dbf header > has a one-byte field to hold the encoding of the file.  For example, > \x03 is code-page 437 MS-DOS. > > My google-fu is apparently not up to the task of locating

Re: ask help for a proble with invalid syntax

2009-10-13 Thread John Machin
On Oct 14, 9:09 am, leo zhao wrote: > I  try to a run a python numpy programe, however the python can't run > this program. > my python version is 2.6.2 , numpy  version is 1.3.0, however, the > program can run in previous numpy version(1.2.0), who can help me to > solve the problem, I will deeply

Re: Why ELIF?

2009-10-11 Thread John Machin
MRAB mrabarnett.plus.com> writes: > > Simon Forman wrote: > [snip] > > > > I'll often do that this way: > > > > args = re.split('\s', line) > > This has the same result, but is shorter and quicker: > > args = line.split() > HUH? Shorter and quicker, yes, but provides much better functiona

Re: Poll: Do you use csv.Sniffer?

2009-09-25 Thread John Machin
On 25/09/2009 7:04 PM, Tim Chase wrote: Why do you need the sniffer? If your client can't do "save as" the same way twice, just read the spreadsheets directly! If I only had one contact and one client, it would be this easy...If you can get multiple points of contact at multiple client sites t

  1   2   3   4   5   6   7   8   9   10   >