Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-12 Thread Jach Feng
moi 在 2022年12月12日 星期一下午5:38:50 [UTC+8] 的信中寫道: > >>> ast.literal_eval("r'\x7a'") == ast.literal_eval("r'z'") > True > >>> ast.literal_eval("r'\xe0'") == ast.literal_eval("r'à'") > True > >>> ast.literal_eval("r'\x9c'") == ast.literal_eval("r'œ'") > False > > - > > > >>> print(codec

Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-09 Thread Jach Feng
> ./cl.py '^M > ' > Input > - > - length 3 > 13 32 10 > From: Python-list on > behalf of Jach Feng > Date: Thursday, December 8, 2022 at 9:31 PM > To: pytho...@python.org > Subject: Re: How to convert a raw string r'xdd' to 'xdd' mo

Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-09 Thread Jach Feng
moi 在 2022年12月9日 星期五晚上11:41:20 [UTC+8] 的信中寫道: > PS C:\humour> py38 sysargwithliteral.py a\x0ab\x09c\x0a\x80uro\x0ax\x08z > cp1252 > a > b c > €uro > z > > PS C:\humour> $a = py38 sysargwithliteral.py a\x0ab\x09c\x0a\x80uro\x0ax\x08z > cp1252 > > PS C:\humour> licp($a) > a U+0061 > b U+0

Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-09 Thread Weatherby,Gerard
) for c in args.data: print(f'{ord(c)} ',end='') print() Using bash on Linux: ./cl.py '^M ' Input - - length 3 13 32 10 From: Python-list on behalf of Jach Feng Date: Thursday, December 8, 2022 at 9:31 PM To: python-list@python.org Subject: Re: How to co

Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-08 Thread Jach Feng
Jach Feng 在 2022年12月7日 星期三上午10:23:20 [UTC+8] 的信中寫道: > s0 = r'\x0a' > At this moment it was done by > > def to1byte(matchobj): > return chr(int('0x' + matchobj.group(1), 16)) > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > But, is it that difficult on doing this simple thing? > >

Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-08 Thread Jach Feng
Jach Feng 在 2022年12月7日 星期三上午10:23:20 [UTC+8] 的信中寫道: > s0 = r'\x0a' > At this moment it was done by > > def to1byte(matchobj): > return chr(int('0x' + matchobj.group(1), 16)) > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > But, is it that difficult on doing this simple thing? > >

Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-08 Thread Peter Otten
On 08/12/2022 02:17, Jach Feng wrote: Peter Otten 在 2022年12月8日 星期四清晨5:17:59 [UTC+8] 的信中寫道: On 07/12/2022 03:23, Jach Feng wrote: s0 = r'\x0a' At this moment it was done by def to1byte(matchobj): return chr(int('0x' + matchobj.group(1), 16)) s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0)

Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-08 Thread Thomas Passin
mine 10 From: Python-list on behalf of Jach Feng Date: Wednesday, December 7, 2022 at 9:27 PM To: python-list@python.org Subject: Re: How to convert a raw string r'xdd' to 'xdd' more gracefully? *** Attention: This is an external email. Use caution responding, opening a

Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-08 Thread Weatherby,Gerard
chobj): return chr(int('0x' + matchobj.group(1), 16)) s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) exam(s0) exam(s1) --- examine \x0a 92 \ 120 x 48 0 97 a examine 10 From: Python-list on behalf of Jach Feng Date: Wednesday, December 7, 2022 at 9:27 PM To: python-list@python.o

Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-07 Thread Jach Feng
Peter Otten 在 2022年12月8日 星期四清晨5:17:59 [UTC+8] 的信中寫道: > On 07/12/2022 03:23, Jach Feng wrote: > > s0 = r'\x0a' > > At this moment it was done by > > > > def to1byte(matchobj): > > return chr(int('0x' + matchobj.group(1), 16)) > > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > > > B

Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-07 Thread Jach Feng
Roel Schroeven 在 2022年12月7日 星期三下午4:42:48 [UTC+8] 的信中寫道: > Op 7/12/2022 om 4:37 schreef Jach Feng: > > MRAB 在 2022年12月7日 星期三上午11:04:43 [UTC+8] 的信中寫道: > > > On 2022-12-07 02:23, Jach Feng wrote: > > > > s0 = r'\x0a' > > > > At this moment it was done by > > > > > > > > def to1byte(matchobj): >

Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-07 Thread Peter Otten
On 07/12/2022 03:23, Jach Feng wrote: s0 = r'\x0a' At this moment it was done by def to1byte(matchobj): return chr(int('0x' + matchobj.group(1), 16)) s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) But, is it that difficult on doing this simple thing? >>> import codecs >>>

Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-07 Thread Jach Feng
Thomas Passin 在 2022年12月7日 星期三中午12:51:32 [UTC+8] 的信中寫道: > On 12/6/2022 9:23 PM, Jach Feng wrote: > > s0 = r'\x0a' > > At this moment it was done by > > > > def to1byte(matchobj): > > return chr(int('0x' + matchobj.group(1), 16)) > > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > >

Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-07 Thread Roel Schroeven
Op 7/12/2022 om 4:37 schreef Jach Feng: MRAB 在 2022年12月7日 星期三上午11:04:43 [UTC+8] 的信中寫道: > On 2022-12-07 02:23, Jach Feng wrote: > > s0 = r'\x0a' > > At this moment it was done by > > > > def to1byte(matchobj): > > return chr(int('0x' + matchobj.group(1), 16)) > > s1 = re.sub(r'\\x([0-9

Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-06 Thread Thomas Passin
On 12/6/2022 9:23 PM, Jach Feng wrote: s0 = r'\x0a' At this moment it was done by def to1byte(matchobj): return chr(int('0x' + matchobj.group(1), 16)) s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) But, is it that difficult on doing this simple thing? --Jach I'm not tota

Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-06 Thread Jach Feng
MRAB 在 2022年12月7日 星期三上午11:04:43 [UTC+8] 的信中寫道: > On 2022-12-07 02:23, Jach Feng wrote: > > s0 = r'\x0a' > > At this moment it was done by > > > > def to1byte(matchobj): > > return chr(int('0x' + matchobj.group(1), 16)) > > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > > > But, is

Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-06 Thread MRAB
On 2022-12-07 02:23, Jach Feng wrote: s0 = r'\x0a' At this moment it was done by def to1byte(matchobj): return chr(int('0x' + matchobj.group(1), 16)) s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) But, is it that difficult on doing this simple thing? You could try this:

How to convert a raw string r'\xdd' to '\xdd' more gracefully?

2022-12-06 Thread Jach Feng
s0 = r'\x0a' At this moment it was done by def to1byte(matchobj): return chr(int('0x' + matchobj.group(1), 16)) s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) But, is it that difficult on doing this simple thing? --Jach -- https://mail.python.org/mailman/listinfo/python-list

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-30 Thread Chris Green
Cameron Simpson wrote: > On 29Aug2020 16:50, Chris Green wrote: > >However the problem appears to be that internally in Python 3 mailbox > >class there is an assumption that it's being given 'ascii'. Here's > >the error (and I'm doing no processing of the message at all):- > > > >Traceback (

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-30 Thread Chris Green
Karsten Hilbert wrote: > > However the problem appears to be that internally in Python 3 mailbox > > class there is an assumption that it's being given 'ascii'. > > Do you really _need_ the mailbox class ? From what you've > written so far my understanding was that you receive data > (bytes) and

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Cameron Simpson
On 29Aug2020 16:50, Chris Green wrote: >However the problem appears to be that internally in Python 3 mailbox >class there is an assumption that it's being given 'ascii'. Here's >the error (and I'm doing no processing of the message at all):- > >Traceback (most recent call last): > File

Aw: Re: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Karsten Hilbert
> Just appending a message as a raw file to a mailbox, doesn't properly > add it as a new message. You need to add a From: line to the front, and > then go through the message and alter any line that begins as "From:" > (and possibly any line that begins with something like ">From:" or > ">>From:"

Re: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Richard Damon
On 8/29/20 3:31 PM, Karsten Hilbert wrote: >> However the problem appears to be that internally in Python 3 mailbox >> class there is an assumption that it's being given 'ascii'. > Do you really _need_ the mailbox class ? From what you've > written so far my understanding was that you receive data

Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Karsten Hilbert
> However the problem appears to be that internally in Python 3 mailbox > class there is an assumption that it's being given 'ascii'. Do you really _need_ the mailbox class ? From what you've written so far my understanding was that you receive data (bytes) and want to append that to a file (which

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Richard Damon
On 8/29/20 11:50 AM, Chris Green wrote: > Chris Green wrote: >> Dennis Lee Bieber wrote: >>> On Fri, 28 Aug 2020 12:26:07 +0100, Chris Green declaimed >>> the >>> following: >>> >>> >>> Maybe I shouldn't but Python 2 has been managing to do so for several years without any issues. I

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Chris Green
Chris Green wrote: > Dennis Lee Bieber wrote: > > On Fri, 28 Aug 2020 12:26:07 +0100, Chris Green declaimed > > the > > following: > > > > > > > > >Maybe I shouldn't but Python 2 has been managing to do so for several > > >years without any issues. I know I *could* put the exceptions in a >

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Chris Green
Dennis Lee Bieber wrote: > On Fri, 28 Aug 2020 12:26:07 +0100, Chris Green declaimed the > following: > > > > >Maybe I shouldn't but Python 2 has been managing to do so for several > >years without any issues. I know I *could* put the exceptions in a > >bucket somewhere and deal with them sep

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Grant Edwards
On 2020-08-28, Chris Green wrote: > Maybe I shouldn't but Python 2 has been managing to do so for several > years without any issues. I know I *could* put the exceptions in a > bucket somewhere and deal with them separately but I'd really rather > not. Then just leave it as bytes and do whateve

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Grant Edwards
On 2020-08-27, Chris Green wrote: > bbb = [b'aaa', b'bbb', b'ccc'] > sss = [] > for i in range(0, 2): > sss.append(str(bbb[i]) > > but that does seem a bit clumsy. Is there a better way? sss = [str(s) for s in bbb] -- Grant -- https://mail.python.org/mailman/listinfo/pyth

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-29 Thread Grant Edwards
On 2020-08-27, Marco Sulla wrote: > Are you sure you want `str()`? > str(b'aaa') > "b'aaa'" > > Probably you want: > > map(lambda x: x.decode(), bbb) If you're an old Scheme or Lisp programmer. :) This is probably the more usual way to spell it: sss = [x.decode() for x in bbb] -- ht

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Cameron Simpson
On 28Aug2020 12:26, Chris Green wrote: >Cameron Simpson wrote: >> POP3 is presumably handing you bytes containing a message. If the >> Python >> email.BytesParser doesn't handle it, stash the raw bytes _elsewhere_ in >> a distinct file in some directory. >> >> with open('evil_msg_bytes', 'wb

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Richard Damon
On 8/28/20 8:44 AM, Chris Green wrote: > Stefan Ram wrote: >> Chris Green writes: >>> Therein lies the problem, the incoming byte stream *isn't* ASCII, it's >>> an E-Mail message which may, for example, have UTF-8 or other encoded >>> characters in it. Hopefully it will have an encoding given in

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Angelico
On Fri, Aug 28, 2020 at 11:24 PM Chris Green wrote: > > Chris Angelico wrote: > > > > Also, if you're parsing an email message, you can and should be doing > > so with respect to the encoding(s) stipulated in the headers, after > > which you will have valid Unicode text. > > > But not all E-Mail

Re: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread D'Arcy Cain
On 2020-08-28 08:30, Richard Damon wrote: > This might be one of the cases where Python 2's lack handling of string > vs bytes was an advantage. For English speaking Americans. > Python2 handled that sort of case quite easily. Python 3 on the other > hand, will have issue converting the byte mess

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Green
Chris Angelico wrote: > > Also, if you're parsing an email message, you can and should be doing > so with respect to the encoding(s) stipulated in the headers, after > which you will have valid Unicode text. > But not all E-Mail messages are 'well behaved', the above works fine if the headers sp

Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Karsten Hilbert
> I want to transport the message into my mbox and Python 3 won't do it > without knowing how it's encoded whereas Python 2 just stuffed it in > there 'as is'. > > I want Python 3's mailbox class to juyst put what I tell it (even if > mis-formatted or mis-encoded) into the mbox. I guess using the

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Richard Damon
On 8/28/20 8:39 AM, Chris Green wrote: > Richard Damon wrote: >> On 8/28/20 7:50 AM, Karsten Hilbert wrote: > No interpreation requires, since parsing failed. Then you can start > dealing with these exceptions. _Do not_ write unparsable messages into > an mbox! > Maybe I shoul

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Angelico
On Fri, Aug 28, 2020 at 10:51 PM Chris Green wrote: > > > One possible solution in Python3 is to decode the byte string using an > > encoding that allows all 256 byte values, so it won't raise any encoding > > errors, just give your possibly non-sense characters for non-ASCII text. > > > But this

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Green
Stefan Ram wrote: > Chris Green writes: > >Therein lies the problem, the incoming byte stream *isn't* ASCII, it's > >an E-Mail message which may, for example, have UTF-8 or other encoded > >characters in it. Hopefully it will have an encoding given in the > >header but that's only if the sender

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Green
Richard Damon wrote: > On 8/28/20 7:50 AM, Karsten Hilbert wrote: > >>> No interpreation requires, since parsing failed. Then you can start > >>> dealing with these exceptions. _Do not_ write unparsable messages into > >>> an mbox! > >>> > >> Maybe I shouldn't but Python 2 has been managing to do

Re: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Angelico
On Fri, Aug 28, 2020 at 10:32 PM Richard Damon wrote: > > This might be one of the cases where Python 2's lack handling of string > vs bytes was an advantage. > > If he was just scanning the message for specific ASCII strings, then not > getting the full message decoded write is unlikely to have b

Re: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Richard Damon
On 8/28/20 7:50 AM, Karsten Hilbert wrote: >>> No interpreation requires, since parsing failed. Then you can start >>> dealing with these exceptions. _Do not_ write unparsable messages into >>> an mbox! >>> >> Maybe I shouldn't but Python 2 has been managing to do so for several >> years without an

Re: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Richard Damon
On 8/28/20 7:50 AM, Karsten Hilbert wrote: >>> No interpreation requires, since parsing failed. Then you can start >>> dealing with these exceptions. _Do not_ write unparsable messages into >>> an mbox! >>> >> Maybe I shouldn't but Python 2 has been managing to do so for several >> years without an

Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Karsten Hilbert
> > No interpreation requires, since parsing failed. Then you can start > > dealing with these exceptions. _Do not_ write unparsable messages into > > an mbox! > > > Maybe I shouldn't but Python 2 has been managing to do so for several > years without any issues. I am inclined to congratulate you

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Green
Cameron Simpson wrote: > On 28Aug2020 08:56, Chris Green wrote: > >Stefan Ram wrote: > >> Chris Angelico writes: > >> >But this is a really good job for a list comprehension: > >> >sss = [str(word) for word in bbb] > >> > >> Are you all sure that "str" is really what you all want? > >> > >Not

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Cameron Simpson
On 28Aug2020 08:56, Chris Green wrote: >Stefan Ram wrote: >> Chris Angelico writes: >> >But this is a really good job for a list comprehension: >> >sss = [str(word) for word in bbb] >> >> Are you all sure that "str" is really what you all want? >> >Not absolutely, you no doubt have been follow

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Green
Cameron Simpson wrote: > On 27Aug2020 23:54, Marco Sulla wrote: > >Are you sure you want `str()`? > > > str(b'aaa') > >"b'aaa'" > > > >Probably you want: > > > >map(lambda x: x.decode(), bbb) > > _And_ you need to know the encoding of the text in the bytes. The above > _assumes_ UTF-8 beca

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Green
Chris Angelico wrote: > On Fri, Aug 28, 2020 at 6:36 AM Chris Green wrote: > > > > This sounds quite an easy thing to do but I can't find how to do it > > elegantly. > > > > I have a list of bytes class objects (i.e. a list containing sequences > > of bytes, which are basically text) and I want t

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Chris Green
Stefan Ram wrote: > Chris Angelico writes: > >But this is a really good job for a list comprehension: > >sss = [str(word) for word in bbb] > > Are you all sure that "str" is really what you all want? > Not absolutely, you no doubt have been following other threads related to this one. :-)

Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-28 Thread Karsten Hilbert
> >Are you sure you want `str()`? > > > str(b'aaa') > >"b'aaa'" > > > >Probably you want: > > > >map(lambda x: x.decode(), bbb) > > _And_ you need to know the encoding of the text in the bytes. The above > _assumes_ UTF-8 because that is the default for bytes.decode, and if > that is _not_ wha

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-27 Thread Cameron Simpson
On 27Aug2020 23:54, Marco Sulla wrote: >Are you sure you want `str()`? > str(b'aaa') >"b'aaa'" > >Probably you want: > >map(lambda x: x.decode(), bbb) _And_ you need to know the encoding of the text in the bytes. The above _assumes_ UTF-8 because that is the default for bytes.decode, and if

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-27 Thread Marco Sulla
Are you sure you want `str()`? >>> str(b'aaa') "b'aaa'" Probably you want: map(lambda x: x.decode(), bbb) -- https://mail.python.org/mailman/listinfo/python-list

Re: Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-27 Thread Chris Angelico
On Fri, Aug 28, 2020 at 6:36 AM Chris Green wrote: > > This sounds quite an easy thing to do but I can't find how to do it > elegantly. > > I have a list of bytes class objects (i.e. a list containing sequences > of bytes, which are basically text) and I want to convert it to a list > of string ob

Python 3 how to convert a list of bytes objects to a list of strings?

2020-08-27 Thread Chris Green
This sounds quite an easy thing to do but I can't find how to do it elegantly. I have a list of bytes class objects (i.e. a list containing sequences of bytes, which are basically text) and I want to convert it to a list of string objects. One of the difficulties of finding out how to do this is

How to convert csv to netcdf please help me python users

2020-05-29 Thread kotichowdary28
Hi all I hope all are doing well please help me how to convert CSV to NetCDF. Im trying but its not working #!/usr/bin/env ipython import pandas as pd import numpy as np import netCDF4 import pandas as pd import xarray as xr stn_precip='ts_sept.csv' orig_precip='ts_sep

Re: How to convert the following IDL program lines to equivalent Python program lines?

2019-11-28 Thread MRAB
On 2019-11-28 15:35, Dennis Lee Bieber wrote: On Thu, 28 Nov 2019 12:45:27 +, Ben Bacarisse declaimed the following: Madhavan Bomidi writes: print,'Column ',J,' of product matrix A*AINV:',format='(1X,A7,I3,A27)' I don't know what the 1X format does. The A7 and A27 formats just see

Re: How to convert the following IDL program lines to equivalent Python program lines?

2019-11-28 Thread Bev In TX
> On Nov 28, 2019, at 9:35 AM, Dennis Lee Bieber wrote: > > Channeling ancient FORTRAN, I'd interpret it as > > 1XSkip one space > A7Seven character alpha > I3Three digit integer > A2727 character alpha > > and it is rather painful when the arguments are litera

Re: How to convert the following IDL program lines to equivalent Python program lines?

2019-11-28 Thread Ben Bacarisse
Madhavan Bomidi writes: > I have the following IDL program lines. I want to write equivalent > Python program lines. Can anyone suggest me equivalent Pythons program > lines? > > # --- 1 --- # > How to handle the format in IDL to Python? > > IDL program line: >

How to convert the following IDL program lines to equivalent Python program lines?

2019-11-28 Thread Madhavan Bomidi
Hi, I have the following IDL program lines. I want to write equivalent Python program lines. Can anyone suggest me equivalent Pythons program lines? # --- 1 --- # How to handle the format in IDL to Python? IDL program line: print,'Column ',J,' of product mat

Re: How to convert a train running program from synchronous to asynchronous?

2019-04-27 Thread Irv Kalb
> On Apr 26, 2019, at 4:18 AM, Arup Rakshit wrote: > > I have modelled which starts running once drivers and stations are assigned > to it. Otherwise, it doesn’t run, really don’t care if passengers are boarded > or not at this moment. :) I think this program can help me to introduce to > the

How to convert a train running program from synchronous to asynchronous?

2019-04-26 Thread Arup Rakshit
I have modelled which starts running once drivers and stations are assigned to it. Otherwise, it doesn’t run, really don’t care if passengers are boarded or not at this moment. :) I think this program can help me to introduce to the Python async programming domain. Here is my program: # - - -

Re: how to convert this psuedo code to python

2018-09-14 Thread Max Zettlmeißl via Python-list
On Fri, Sep 14, 2018 at 2:37 PM, Noel P. CUA wrote: > compose your own octave script to calculate the machine > epsilon. Analyze the code. > > epsilon = 1 > DO > IF (epsilon+1<=1) EXIT > epsilon = epsilon/2 > END DO > epsilon = 2 x epsilon > epsilon = 1 while epsilon + 1 > 1: epsilon = epsi

how to convert this psuedo code to python

2018-09-14 Thread Noel P. CUA
compose your own octave script to calculate the machine epsilon. Analyze the code. epsilon = 1 DO IF (epsilon+1<=1) EXIT epsilon = epsilon/2 END DO epsilon = 2 x epsilon -- *This email and any files transmitted with it are confidential and intended solely for the use of the individual or enti

Re: how to convert json to csv with python?

2017-06-03 Thread Peter Otten
Ho Yeung Lee wrote: > after edit the file, > > Traceback (most recent call last): > File "json2csv.py", line 148, in > loader.load(args.json_file) > File "json2csv.py", line 53, in load > self.process_each(json.load(json_file)) > File "C:\Python27\lib\json\__init__.py", line 291, i

Re: how to convert json to csv with python?

2017-06-03 Thread Ho Yeung Lee
after edit the file, Traceback (most recent call last): File "json2csv.py", line 148, in loader.load(args.json_file) File "json2csv.py", line 53, in load self.process_each(json.load(json_file)) File "C:\Python27\lib\json\__init__.py", line 291, in load **kw) File "C:\Python27

Re: how to convert json to csv with python?

2017-06-03 Thread Chris Warrick
On 3 June 2017 at 13:00, Ho Yeung Lee wrote: > i use > https://github.com/evidens/json2csv > > Error: > Traceback (most recent call last): > File "json2csv.py", line 148, in > loader.load(args.json_file) > File "json2csv.py", line 53, in load > self.process_each(json.load(json_file))

how to convert json to csv with python?

2017-06-03 Thread Ho Yeung Lee
i use https://github.com/evidens/json2csv Error: Traceback (most recent call last): File "json2csv.py", line 148, in loader.load(args.json_file) File "json2csv.py", line 53, in load self.process_each(json.load(json_file)) File "C:\Python27\lib\json\__init__.py", line 291, in load

how to convert this container back to format build result?

2017-04-10 Thread Ho Yeung Lee
http://construct.readthedocs.io/en/latest/basics.html format.build can build the hex string, but after edit attribute of the format parse result it is a container, how to convert this container back to format build result? #format.parse(format.build(dict(width=3,height=2,pixels=[7,8,9,11,12,13

Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-25 Thread Steve D'Aprano
On Sun, 25 Sep 2016 09:08 am, Thomas 'PointedEars' Lahn wrote: > Christian Gollwitzer wrote: > >> Am 17.09.16 um 23:19 schrieb Thomas 'PointedEars' Lahn: >>> Peng Yu wrote: Hi, I want to convert strings in which the characters with accents should be converted to the ones without accents

Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-25 Thread Christian Gollwitzer
Am 25.09.16 um 01:08 schrieb Thomas 'PointedEars' Lahn: Christian Gollwitzer wrote: Am 17.09.16 um 23:19 schrieb Thomas 'PointedEars' Lahn: Peng Yu wrote: Hi, I want to convert strings in which the characters with accents should be converted to the ones without accents. […] […] ./main.py Fö

Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-25 Thread Martin Schöön
Den 2016-09-25 skrev wxjmfa...@gmail.com : > > As an European guy, I recommend to use the characters > set used in the "official" font families used in Germany: > BundesSerif / BundesSans. > > See > https://styleguide.bundesregierung.de/Webs/SG/DE/PrintMedien/Basiselemente/Schriften/schriften_node.

Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-18 Thread Steven D'Aprano
On Sunday 18 September 2016 17:51, Terry Reedy wrote: > On 9/18/2016 2:45 AM, Steven D'Aprano wrote: > >> It doesn't matter whether you call them "accent" like most people do, or >> "diacritics" as linguists do. > > I am a native born American and I have never before heard or seen > non-accent d

Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-18 Thread not1xor1
Il 18/09/2016 08:45, Steven D'Aprano ha scritto: integral part of the letter, like the horizonal stroke in English t or the vertical bar in English p and b, and in some languages they are modifiers, well... that is the Latin alphabet English has no T, P or B (or any other character) but is jus

Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-18 Thread Marko Rauhamaa
Thorsten Kampe : > * Terry Reedy (Sun, 18 Sep 2016 03:51:40 -0400) >> On 9/18/2016 2:45 AM, Steven D'Aprano wrote: >> > It doesn't matter whether you call them "accent" like most people do, or >> > "diacritics" as linguists do. >> >> I am a native born American and I have never before heard or se

Re: How to convert 'ö' to 'oe' or 'o' (or other si =?utf-8?Q?milar_things)_in_a_string??=

2016-09-18 Thread Thorsten Kampe
* Terry Reedy (Sun, 18 Sep 2016 03:51:40 -0400) > > On 9/18/2016 2:45 AM, Steven D'Aprano wrote: > > > It doesn't matter whether you call them "accent" like most people do, or > > "diacritics" as linguists do. > > I am a native born American and I have never before heard or seen > non-accent di

Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-18 Thread Martin Schöön
Den 2016-09-17 skrev Marko Rauhamaa : > Martin Schöön : >> Related anecdote from Phoenix AZ. By now you have noticed my family >> name: Schöön. On airline tickets and boarding passes in the U.S. it >> gets spelled Schoeoen. > > Do Swedes do that German thing, too? If you have to write Finnish > wit

Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-18 Thread Christian Gollwitzer
Am 17.09.16 um 23:19 schrieb Thomas 'PointedEars' Lahn: Peng Yu wrote: Hi, I want to convert strings in which the characters with accents should be converted to the ones without accents. Why? […] ./main.py Förstemann AFAIK, “ä”, “ö”, and “ü” are not accented characters in any natural lang

Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-18 Thread Terry Reedy
On 9/18/2016 2:45 AM, Steven D'Aprano wrote: It doesn't matter whether you call them "accent" like most people do, or "diacritics" as linguists do. I am a native born American and I have never before heard or seen non-accent diacritic marks called 'accents'. Accents indicate stress. Other d

Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-17 Thread Steven D'Aprano
On Sunday 18 September 2016 15:59, Thorsten Kampe wrote: > * Martin Schöön (17 Sep 2016 20:20:12 GMT) >> >> Den 2016-09-17 skrev Kouli : >> > Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode. >> > >> > Kouli >> > >> > On Sat, Sep 17, 2016 at 6:12 PM, Peng Yu wrote: >> >>

Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-17 Thread Steven D'Aprano
On Sunday 18 September 2016 13:30, Peng Yu wrote: > On Sat, Sep 17, 2016 at 3:20 PM, Martin Schöön > wrote: >> Den 2016-09-17 skrev Kouli : >>> Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode. > > I don't find a way to make it print oe for ö. Could anybody please > advis

Re: How to convert 'ö' to 'oe' or 'o' (or other si =?utf-8?Q?milar_things)_in_a_string??=

2016-09-17 Thread Thorsten Kampe
* Martin Schöön (17 Sep 2016 20:20:12 GMT) > > Den 2016-09-17 skrev Kouli : > > Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode. > > > > Kouli > > > > On Sat, Sep 17, 2016 at 6:12 PM, Peng Yu wrote: > >> Hi, I want to convert strings in which the characters with accents >

Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-17 Thread Steve D'Aprano
On Sun, 18 Sep 2016 07:19 am, Thomas 'PointedEars' Lahn wrote: > AFAIK, “ä”, “ö”, and “ü” are not accented characters in any natural > language, but characters of their own (umlauts). Are you saying that English is not a natural language? -- Steve “Cheer up,” they said, “things could be wo

Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-17 Thread Peng Yu
On Sat, Sep 17, 2016 at 3:20 PM, Martin Schöön wrote: > Den 2016-09-17 skrev Kouli : >> Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode. I don't find a way to make it print oe for ö. Could anybody please advise what is the correct way to do it? ==> main.py <== #!/usr/bin

Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-17 Thread Marko Rauhamaa
Martin Schöön : > Related anecdote from Phoenix AZ. By now you have noticed my family > name: Schöön. On airline tickets and boarding passes in the U.S. it > gets spelled Schoeoen. Do Swedes do that German thing, too? If you have to write Finnish without ä and ö, you simply leave out the dots. (On

Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-17 Thread Martin Schöön
Den 2016-09-17 skrev Kouli : > Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode. > > Kouli > > On Sat, Sep 17, 2016 at 6:12 PM, Peng Yu wrote: >> Hi, I want to convert strings in which the characters with accents >> should be converted to the ones without accents. Here is m

Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-17 Thread Kouli
Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode. Kouli On Sat, Sep 17, 2016 at 6:12 PM, Peng Yu wrote: > Hi, I want to convert strings in which the characters with accents > should be converted to the ones without accents. Here is my current > code. > > =

How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

2016-09-17 Thread Peng Yu
Hi, I want to convert strings in which the characters with accents should be converted to the ones without accents. Here is my current code. $ cat main.sh #!/usr/bin/env bash # vim: set noexpandtab tabstop=2: set -v ./main.py Förstemann ./main.py Frédér8ic@ $ cat main.p

Re: how to convert code that uses cmp to python3

2016-04-09 Thread Paul Rubin
Ben Finney writes: > The ‘cmp’ implementation must decide *at least* between three > conditions... The implementation of ‘__lt__’ and the implementation > of ‘__eq__’ each only need to decide two conditions (true, false). > If you're saying the latter implementation is somehow *more* expensive >

Re: how to convert code that uses cmp to python3

2016-04-09 Thread Marko Rauhamaa
Antoon Pardon : > And when I need some personal object as a key, I can avoid the > duplication by using some kind of cmp cache when I implement __lt__ > and family. Yes, that's what you can do in rare, extreme cases where key comparison takes a long time. For caching, you will simply need to requ

Re: how to convert code that uses cmp to python3

2016-04-09 Thread Antoon Pardon
Op 09-04-16 om 17:31 schreef Chris Angelico: > On Sun, Apr 10, 2016 at 1:24 AM, Antoon Pardon > wrote: >> >> So? I need a structure that can easily give me an answer to the >> following: Given key1 and key2 what are the the keys between them >> with their corresponding values. As long as a dict ca

Re: how to convert code that uses cmp to python3

2016-04-09 Thread Random832
On Sat, Apr 9, 2016, at 07:49, Ben Finney wrote: > I find that a dubious claim. > > The ‘cmp’ implementation must decide *at least* between three > conditions: less-than, equal-to, greater-than. That is *at least* two > inflection points. Yes, but in a sequence it can decide that at each element,

Re: how to convert code that uses cmp to python3

2016-04-09 Thread Chris Angelico
On Sun, Apr 10, 2016 at 1:24 AM, Antoon Pardon wrote: > Op 09-04-16 om 16:41 schreef Chris Angelico: > >> >> In this case, you're likely to end up with large branches of your tree >> that have the same prefix. (And if you don't, your iterations are all >> going to end early anyway, so the comparis

Re: how to convert code that uses cmp to python3

2016-04-09 Thread Antoon Pardon
Op 09-04-16 om 16:41 schreef Chris Angelico: > > In this case, you're likely to end up with large branches of your tree > that have the same prefix. (And if you don't, your iterations are all > going to end early anyway, so the comparison is cheap.) A data > structure that takes this into account

Re: how to convert code that uses cmp to python3

2016-04-09 Thread Marko Rauhamaa
Antoon Pardon : > Now this probably is not a problem most of the times, but when you > work with tree's this kind of comparison to make a three way decision > happens often and the lower you descend in the tree, the close your > argument will be with the keys of the nodes you visit, making it more

Re: how to convert code that uses cmp to python3

2016-04-09 Thread Chris Angelico
On Sun, Apr 10, 2016 at 12:25 AM, Antoon Pardon wrote: > Let me give you an artifical example to show what can happen. The keys are all > iterables of equal lengths with integers as elements. > > Then this could be the cmp function: > > def cmp(ob1, ob2): > itr1 = iter(ob1) > itr2 = iter(o

Re: how to convert code that uses cmp to python3

2016-04-09 Thread Antoon Pardon
Op 09-04-16 om 13:49 schreef Ben Finney: > Antoon Pardon writes: > >> You don't seem to understand. I only do two comparisons and no the >> equality is not necesarrily cheaper. >> >> I am talking about the difference between the following two: >> >> if arg.key < node.key: # possible expensi

Re: how to convert code that uses cmp to python3

2016-04-09 Thread Ben Finney
Antoon Pardon writes: > You don't seem to understand. I only do two comparisons and no the > equality is not necesarrily cheaper. > > I am talking about the difference between the following two: > > if arg.key < node.key: # possible expensive computation > go_left() > elif arg.k

Re: how to convert code that uses cmp to python3

2016-04-09 Thread Antoon Pardon
Op 08-04-16 om 16:25 schreef Chris Angelico: > On Sat, Apr 9, 2016 at 12:20 AM, Antoon Pardon > wrote: >>> You only need ONE comparison, and the other is presumed to be its >>> opposite. When, in the Python 3 version, would you need to compare >>> twice? >> >> About 50% of the time. When I travers

Re: how to convert code that uses cmp to python3

2016-04-08 Thread Marko Rauhamaa
Ian Kelly : > On Fri, Apr 8, 2016 at 10:33 AM, Marko Rauhamaa wrote: >> Ian Kelly : >> >>> That's fine for those operations and probably insert, but how do you >>> search an AVL tree for a specific key without also using __eq__? >> >> Not needed: >> >>

Re: how to convert code that uses cmp to python3

2016-04-08 Thread Ian Kelly
On Fri, Apr 8, 2016 at 10:33 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> That's fine for those operations and probably insert, but how do you >> search an AVL tree for a specific key without also using __eq__? > > Not needed: > > ===

  1   2   3   4   5   6   >