Re: Feeding the trolls

2018-06-21 Thread Anssi Saari
D'Arcy Cain  writes:

> One of these days I will have to figure out how to block replies to the
> trolls as well.

Benefit of reading the mailing list via nntp (i.e. gmane): can easily
score down follow-ups to annoying people in addition to their
posts. Well, assuming a decent newsreader.

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


translating foreign data

2018-06-21 Thread Ethan Furman
I need to translate numeric data in a string format into a binary format.  I know there are at least two different 
methods of representing parts less that 1, such as "10.5" and "10,5".  The data is encoded using code pages, and can 
vary depending on the file being read (so I can't rely on current locale settings).


I'm sure this is a solved problem, but I'm not finding those solutions.  Any 
pointers?

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


write the values of an ordered dictionary into a file

2018-06-21 Thread Ganesh Pal
Hi Team



I need to write the values of an ordered dictionary into a file . All
values should be in a single row with a header list



*Example:*



*student = [("NAME", "John"),*

*   ("AGE", 28),*

*   ("SCORE", 13),*

*   ("YEAR", 2018),*

*   ("FEE", 250)]*

*student = OrderedDict(student)*



*The OrderedDict Should be append at the end of the file as as shown below.*


*# tail -2  /tmp/student_record.txt *

*.*

*||STUDENT NAME||STUDENT AGE||MARKS SCORED||PASSED YEAR||FEES PAID||*

*||John||  28   ||  13|| 2018  || 250 ||*





Questions:


(1) Below is my partial solution , any comments and suggestions ( I am not
to get the “||” delimiter correctly, trying it )



#!/usr/bin/python



# A Python program to write the values of an OderedDict into a file

# The values should be formatted correctly under its headers



from collections import OrderedDict

tmp = '/tmp/student_record.txt'



student = [("NAME", "John"),

   ("AGE", 28),

   ("SCORE", 13),

   ("YEAR", 2018),

   ("FEE", 250)]

student = OrderedDict(student)



header_list = ["STUDENT NAME", "STUDENT AGE", "MARKS SCORED", "PASSED YEAR",

"FEES PAID"]

header_string = '||' + '||'.join(header_list) + '||'



with open(tmp, 'a') as fd:

 for item in header_string:

 fd.write("%s" % (item))



 for value in student.values():

 fd.write("\n")

 fd.write("||")

 fd.write("%s" % (value))





*output:*



*root@X1:/Play_ground/SPECIAL_TYPES# cat /tmp/student_record.txt*

*||STUDENT NAME||STUDENT AGE||MARKS SCORED||PASSED YEAR||FEES PAID||*

*||John*

*||28*

*||13*

*||2018*





(2)Any alternative way to solve this easily and store the data  in the
requested format (can I still use cvs writer to format this)





I am a Linux user with Python 2.7



Regards,
Ganesh
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: write the values of an ordered dictionary into a file

2018-06-21 Thread Peter Pearson
On Thu, 21 Jun 2018 22:41:48 +0530, Ganesh Pal  wrote:
[snip]
[what I think OP wants:]
>
> *.*
>
> *||STUDENT NAME||STUDENT AGE||MARKS SCORED||PASSED YEAR||FEES PAID||*
>
> *||John||  28   ||  13|| 2018  || 250 ||*
>
>
> Questions:
>
> (1) Below is my partial solution , any comments and suggestions ( I am not
> to get the “||” delimiter correctly, trying it )
>
> #!/usr/bin/python
> # A Python program to write the values of an OderedDict into a file
> # The values should be formatted correctly under its headers
>
> from collections import OrderedDict
>
> tmp = '/tmp/student_record.txt'
> student = [("NAME", "John"),
>("AGE", 28),
>("SCORE", 13),
>("YEAR", 2018),
>("FEE", 250)]
>
> student = OrderedDict(student)
> header_list = ["STUDENT NAME", "STUDENT AGE", "MARKS SCORED", "PASSED YEAR",
> "FEES PAID"]
>
> header_string = '||' + '||'.join(header_list) + '||'
> with open(tmp, 'a') as fd:
>  for item in header_string:
>  fd.write("%s" % (item))
>
>  for value in student.values():
>  fd.write("\n")
>  fd.write("||")
>  fd.write("%s" % (value))
>
> *output:*
> *root@X1:/Play_ground/SPECIAL_TYPES# cat /tmp/student_record.txt*
> *||STUDENT NAME||STUDENT AGE||MARKS SCORED||PASSED YEAR||FEES PAID||*
> *||John*
> *||28*
> *||13*
> *||2018*
[snip]

You don't say which aspects of this output you find unsatisfactory and
want help with, but . . .

 - You're writing "\n" in front of every *field*, when you only want to
   write it in front of every line; and

 - To make the columns line up right, you'll want to specify the widths
   of the character strings being written, e.g., using "%10s" in place
   of "%s".

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: translating foreign data

2018-06-21 Thread Peter Pearson
On Thu, 21 Jun 2018 10:12:27 -0700, Ethan Furman  wrote:
> I need to translate numeric data in a string format into a binary
> format.  I know there are at least two different methods of
> representing parts less that 1, such as "10.5" and "10,5".  The data
> is encoded using code pages, and can vary depending on the file being
> read (so I can't rely on current locale settings).
>
> I'm sure this is a solved problem, but I'm not finding those
> solutions.  Any pointers?

Do you also have to accommodate the possibility that one thousand
might be written "1,000" or "1.000"?

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: write the values of an ordered dictionary into a file

2018-06-21 Thread MRAB

On 2018-06-21 18:11, Ganesh Pal wrote:
> Hi Team
>
> I need to write the values of an ordered dictionary into a file . All
> values should be in a single row with a header list
>
> *Example:*
>
> *student = [("NAME", "John"),*
> *   ("AGE", 28),*
> *   ("SCORE", 13),*
> *   ("YEAR", 2018),*
> *   ("FEE", 250)]*
> *student = OrderedDict(student)*
>
> *The OrderedDict Should be append at the end of the file as as shown 
below.*

>
> *# tail -2  /tmp/student_record.txt *
> *.*
> *||STUDENT NAME||STUDENT AGE||MARKS SCORED||PASSED YEAR||FEES PAID||*
> *||John||  28   ||  13|| 2018  || 250 ||*
>
>
> Questions:
>
> (1) Below is my partial solution , any comments and suggestions ( I 
am not

> to get the “||” delimiter correctly, trying it )
>
> #!/usr/bin/python
>
> # A Python program to write the values of an OderedDict into a file
> # The values should be formatted correctly under its headers
>
> from collections import OrderedDict
> tmp = '/tmp/student_record.txt'
>
> student = [("NAME", "John"),
> ("AGE", 28),
> ("SCORE", 13),
> ("YEAR", 2018),
> ("FEE", 250)]
>
> student = OrderedDict(student)
>
> header_list = ["STUDENT NAME", "STUDENT AGE", "MARKS SCORED", "PASSED 
YEAR",

>  "FEES PAID"]
>
> header_string = '||' + '||'.join(header_list) + '||'
>
> with open(tmp, 'a') as fd:

header_string is already a string, so here you're just iterating over 
the characters of that string:


>   for item in header_string:
>   fd.write("%s" % (item))
>
You can write it more simple like this:

fd.write("%s\n" % header_string)

Here you're writing a newline before each of the fields/columns:

>   for value in student.values():
>   fd.write("\n")
>   fd.write("||")
>   fd.write("%s" % (value))
>
>
> *output:*
>
> *root@X1:/Play_ground/SPECIAL_TYPES# cat /tmp/student_record.txt*
> *||STUDENT NAME||STUDENT AGE||MARKS SCORED||PASSED YEAR||FEES PAID||*
> *||John*
> *||28*
> *||13*
> *||2018*
>
>
> (2)Any alternative way to solve this easily and store the data  in the
> requested format (can I still use cvs writer to format this)
>
>
> I am a Linux user with Python 2.7
>
What I would do is measure the widths of the each heading and of each 
value and then pad them out to the longest:



header_list = ["STUDENT NAME", "STUDENT AGE", "MARKS SCORED", "PASSED 
YEAR", "FEES PAID"]

header_widths = [len(header) for header in header_list]

value_list = [str(value) for value in student.values()]
value_widths = [len(value) for value in value_list]

column_widths = [max(header_width, value_width) for header_width, 
value_width in zip(header_widths, value_widths)]


with open(tmp, 'a') as fd:
fd.write('||' + '||'.join(header.ljust(width) for header, width in 
zip(header_list, column_widths)) + '||\n')
fd.write('||' + '||'.join(value.ljust(width) for value, width in 
zip(value_list, column_widths)) + '||\n')

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


Re: write the values of an ordered dictionary into a file

2018-06-21 Thread Peter Otten
Ganesh Pal wrote:

> Hi Team

There is no team, just some random guys on the net. Sorry to disappoint 
you...

> I need to write the values of an ordered dictionary into a file . All
> values should be in a single row with a header list
> 
> 
> 
> *Example:*
> 
> 
> 
> *student = [("NAME", "John"),*
> 
> *   ("AGE", 28),*
> 
> *   ("SCORE", 13),*
> 
> *   ("YEAR", 2018),*
> 
> *   ("FEE", 250)]*
> 
> *student = OrderedDict(student)*
> 
> 
> 
> *The OrderedDict Should be append at the end of the file as as shown
> below.*
> 
> 
> *# tail -2  /tmp/student_record.txt *
> 
> *.*
> 
> *||STUDENT NAME||STUDENT AGE||MARKS SCORED||PASSED YEAR||FEES PAID||*
> 
> *||John||  28   ||  13|| 2018  || 250 ||*


Here's one way, written in Python 3.

widths = [len(ch) for ch in header_list]

def print_row(values, widths=widths, file=None):
print(
"||",
"||".join("{:^{}}".format(v, w) for v, w in zip(values, widths)),
"||", sep="", file=file
)

print_row(header_list)
print_row(student.values())

In Python 2 it should work after

from __future__ import print_function

or by replacing print() with a few file.write() calls.


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


Re: syntax difference

2018-06-21 Thread Alister via Python-list
On Wed, 20 Jun 2018 11:41:23 -0700, bart4858 wrote:

> The actual interpreter code is irrelevant. Switch would be a feature of
> the language being interpreted, not of the interpreter.
> 
> If the task is to match an expression X against a variety of values,
> then expressing that as a switch means the interpreter /could/ use a
> jump table (of labels within the byte code), rather than execute a chain
> of X==Y tests within byte code. So, evaluate X once then it could be a
> single byte code op.
> 
> At least, it will know that exactly the same X value is being tested. So
> you evaluate it once then keep it on the stack.
> 
> Think of Switch as another kind if hint.

which can be implemented in python by putting function calls as members 
of a list or dictionary

switch=[case1,case2,case3]
switch[a]()

(although i personally would still like to see a switch if anyone can 
come up with a suitable syntax that does not break the rest of the python 
philosophy wtr indentation.)



-- 
There are more things in heaven and earth,
Horatio, than are dreamt of in your philosophy.
-- Wm. Shakespeare, "Hamlet"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: translating foreign data

2018-06-21 Thread codewizard
On Thursday, June 21, 2018 at 1:08:35 PM UTC-4, Ethan Furman wrote:
> I need to translate numeric data in a string format into a binary format.  I 
> know there are at least two different 
> methods of representing parts less that 1, such as "10.5" and "10,5".  The 
> data is encoded using code pages, and can 
> vary depending on the file being read (so I can't rely on current locale 
> settings).
> 
> I'm sure this is a solved problem, but I'm not finding those solutions.  Any 
> pointers?
> 
> --
> ~Ethan~

Try this StackOverflow answer: https://stackoverflow.com/a/17815252

Regards,
Igor.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: translating foreign data

2018-06-21 Thread Ethan Furman

On 06/21/2018 10:36 AM, Peter Pearson wrote:

On Thu, 21 Jun 2018 10:12:27 -0700, Ethan Furman  wrote:

I need to translate numeric data in a string format into a binary
format.  I know there are at least two different methods of
representing parts less that 1, such as "10.5" and "10,5".  The data
is encoded using code pages, and can vary depending on the file being
read (so I can't rely on current locale settings).

I'm sure this is a solved problem, but I'm not finding those
solutions.  Any pointers?


Do you also have to accommodate the possibility that one thousand
might be written "1,000" or "1.000"?


Nope, just the decimal character.

--
~Ethan~


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


Re: translating foreign data

2018-06-21 Thread Ethan Furman

On 06/21/2018 12:07 PM, codewiz...@gmail.com wrote:

On Thursday, June 21, 2018 at 1:08:35 PM UTC-4, Ethan Furman wrote:



I need to translate numeric data in a string format into a binary format.  I 
know there are at least two different
methods of representing parts less that 1, such as "10.5" and "10,5".  The data 
is encoded using code pages, and can
vary depending on the file being read (so I can't rely on current locale 
settings).

I'm sure this is a solved problem, but I'm not finding those solutions.  Any 
pointers?


Try this StackOverflow answer: https://stackoverflow.com/a/17815252


--> import locale
--> a = u'545,545.'
--> locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
'en_US.UTF-8'

The problem there is it sets the locale for the entire process -- I just need the conversion step for individual pieces 
of data without modifying the user's settings.


--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: syntax difference

2018-06-21 Thread bart4858
Alister:
==
which can be implemented in python by putting function calls as members 
of a list or dictionary 

switch=[case1,case2,case3] 
switch[a]() 
==
This is the approach you might use when you don't have a proper switch. It 
could be done in C that way.

Problems: the code for the different cases is not localised. You have to think 
up function names. The cases must be listed in that order. If the first case is 
not zero, you have to deal with that. Gaps in the sequence are problematical. 
You need a way of detecting the default case. There is no association between 
case number and its entry. The case numbers may be named values, so won't know 
what order they need to be in.

Using a dict will solve some of that, but its not clear what overheads there 
are in setting up the dict.

A proper switch also allows lists, ranges and scalars, or any mix, for each 
case block. It's not clear how a dict can be used for that, without adding 
another layer of processing which defeats part of the purpose in having switch.

Above all, you lose the clarity of a proper switch construct.

Alister:
==
(although i personally would still like to see a switch if anyone can 
come up with a suitable syntax that does not break the rest of the python 
philosophy wtr indentation.) 
==

The syntax is a minor detail. The biggest problem with adding an int-based 
switch to Python that uses a jump-table is that that requires the case values 
to be known at compile-time. Usually they won't be.

I came up with a way around this which used tentative byte code which is fixed 
up the first time it is executed. But that is rather hairy, and it means case 
values are fixed: if A is a case value of 10, then if later on it is 20, it 
will be treated as 10 still.

For such reasons it is unlikely to make it into Python in that form.

However a switch statement can still be useful for its expressiveness, and 
implemented as sequential tests.

-- 
Bart
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: translating foreign data

2018-06-21 Thread Ben Bacarisse
Ethan Furman  writes:
 
> I need to translate numeric data in a string format into a binary
> format.  I know there are at least two different methods of
> representing parts less that 1, such as "10.5" and "10,5".  The data
> is encoded using code pages, and can vary depending on the file being
> read (so I can't rely on current locale settings).
>
> I'm sure this is a solved problem, but I'm not finding those
> solutions.  Any pointers?

You say "at least two" and give two but not knowing the others will hamper
anyone trying to help.  (I appreciate that you may not yet know if there
are to be any others.)

You say in a followup that you don't need to worry about digit grouping
marks (like thousands separators) so I'm not sure what the problem is.
Can't you just replace ',' with '.' a proceed as if you had only one
representation?

The code page remark is curious.  Will some "code pages" have digits
that are not ASCII digits?

-- 
Ben.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: translating foreign data

2018-06-21 Thread Peter Otten
Ethan Furman wrote:

> I need to translate numeric data in a string format into a binary format. 
> I know there are at least two different
> methods of representing parts less that 1, such as "10.5" and "10,5".  The
> data is encoded using code pages, and can vary depending on the file being
> read (so I can't rely on current locale settings).
> 
> I'm sure this is a solved problem, but I'm not finding those solutions. 
> Any pointers?

There's babel

http://babel.pocoo.org/en/latest/numbers.html#parsing-numbers

though I'm not sure what to think of the note below the linked paragraph.


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


Re: Feeding the trolls

2018-06-21 Thread mm0fmf

On 21/06/2018 05:02, Abdur-Rahmaan Janhangeer wrote:

by building a custom py-based mail client maybe ^^_

Abdur-Rahmaan Janhangeer
https://github.com/Abdur-rahmaanJ

On Wed, 20 Jun 2018, 17:18 D'Arcy Cain,  wrote:


On 2018-06-20 08:10 AM, Tim Golden wrote:

[... snip discussions about Bart's language ...]

Wearing my moderator hat

Can we take the "Bart's language vs Python Show" to some other forum,
please? We've already gone over this ground again and again and it isn't
helping the signal-to-noise ratio here on the Python list /
comp.lang.python


Thank you.  Many of us have blocked rick and bart years ago.  If you are
just going to feed the trolls we have to see their nonsense anyway.
Just email them privately if you really feel the need to vent.

One of these days I will have to figure out how to block replies to the
trolls as well.

--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
--
https://mail.python.org/mailman/listinfo/python-list



Design requirements for python newsreader client:

1. Block all top posters

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


Re: translating foreign data

2018-06-21 Thread George Fischhof
Peter Otten <__pete...@web.de> ezt írta (időpont: 2018. jún. 21., Cs,
22:45):

> Ethan Furman wrote:
>
> > I need to translate numeric data in a string format into a binary
> format.
> > I know there are at least two different
> > methods of representing parts less that 1, such as "10.5" and "10,5".
> The
> > data is encoded using code pages, and can vary depending on the file
> being
> > read (so I can't rely on current locale settings).
> >
> > I'm sure this is a solved problem, but I'm not finding those solutions.
> > Any pointers?
>
> There's babel
>
> http://babel.pocoo.org/en/latest/numbers.html#parsing-numbers
>
> though I'm not sure what to think of the note below the linked paragraph.
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list


Hi,

if you have several values in a file, then you probably you can check the
delimiters: there is only one decimal separator,
- so if you find a number with 2 separators, then a rightmost is a the
decimal
- if you found only one type, then that is the decimal
- try to check the separator from right to left
- if you found 4 digits right to a separator, then that is the decimal
separator
etc (maybe wikipedia should be checked for other separators.
Other thousand separators used: space, apostrophe, and in India after the
first thousand separator the separation is done with two numbers, not three

And if you are able to identify the encoding codepage, then you should
follow what the codepage says

Another help can be if know the possible value range of the numbers (maybe
it should be asked ...)


George
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: translating foreign data

2018-06-21 Thread Gregory Ewing

George Fischhof wrote:


- if you found only one type, then that is the decimal


Only if you're sure that all numbers contain a decimal separator.
Otherwise there's no way to be sure in general.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Feeding the trolls

2018-06-21 Thread Steven D'Aprano
On Thu, 21 Jun 2018 21:49:15 +0100, mm0fmf wrote:

[snip unnecessary quoting]
> Design requirements for python newsreader client:
> 
> 1. Block all top posters

I think it would be far more useful to block bottom-posters who don't 
snip irrelevant quoted text.



-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

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


Re: translating foreign data

2018-06-21 Thread Cameron Simpson

On 21Jun2018 10:12, Ethan Furman  wrote:
I need to translate numeric data in a string format into a binary 
format.  I know there are at least two different methods of 
representing parts less that 1, such as "10.5" and "10,5".  The data 
is encoded using code pages, and can vary depending on the file being 
read (so I can't rely on current locale settings).


I'm sure this is a solved problem, but I'm not finding those solutions.  Any 
pointers?


It sounds like you're conflating two problems:

- the file character data encoding

- the numeric representation

Can't you just read the file as a text file using the correct 
codepage->decoding setting to get strings, _then_ parse numbers either with 
some clunky regexp based approach or some flexible external library for common 
numeric forms? (Someone suggested babel, I've never used it.)


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Feeding the trolls

2018-06-21 Thread Abdur-Rahmaan Janhangeer
aie maybe we can learn then warn ! mail sender is top poster

Abdur-Rahmaan Janhangeer
https://github.com/Abdur-rahmaanJ

Design requirements for python newsreader client:
>
> 1. Block all top posters
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Feeding the trolls

2018-06-21 Thread Gregory Ewing

Steven D'Aprano wrote:

On Thu, 21 Jun 2018 21:49:15 +0100, mm0fmf wrote:


Design requirements for python newsreader client:

1. Block all top posters


I think it would be far more useful to block bottom-posters who don't 
snip irrelevant quoted text.


In the early days of Usenet, it was common for news servers to
refuse posts that didn't have a high enough ratio of new to
quoted text.
.
.
.
.
.
.
.
.
.
.
.
.
.
It was easily defeated, of course. :-) But at least it forced you
to think about the issue.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


ironpython not support py3.6

2018-06-21 Thread fantasywangxg
We have a project implemented with c# and python, iron python is  a good choice 
for us to integrate these two tech together but iron python not support python 
3.6 yet, any suggest for this?
-- 
https://mail.python.org/mailman/listinfo/python-list