Re: recommends of redesign OO feature of python !!!

2018-10-25 Thread Andre Müller
Troll detected!

If you don't like Python, don't use it. Very simple.
The concept of Python is good as it is.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: help me ?

2018-02-27 Thread Andre Müller
Hello,

it's a duplicate:
https://python-forum.io/Thread-Working-with-lists-homework-2

I have seen this more than one time. We don't like it. You keep people busy
with one question at different places.

You need two lists and one empty list. One outer loop iterating over the
first list and one inner loop iterating over the second list. In the inner
loop you concatenate the two elements from the outer-loop and inner-loop.
Then you append them to the empty list. This text is 10 times longer as the
source code...

Complicated solution:

from string import ascii_lowercase as letter
list1 = [str(i) + c for i in range(1,4) for c in letter[:3]]
list2 = [c[::-1] for c in list1]

But this won't help you. Before you understand the code above, you have to
understand for-loops and nested for-loops. Then you can proceed with list
comprehensions. But I don't see that your intention is to learn and
understand Python. You just want to finish your homework, which bother you.

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


Re: "Programs" folder not found.

2018-02-15 Thread Andre Müller
Look in %localappdata%\Programs\Python

Enerel Amgalan via Python-list  schrieb am Do., 15.
Feb. 2018 um 14:05 Uhr:

>
> Hello! So I downloaded “Python” program in C:>Users>(my
> name)>AppData>Local>Programs>Python.And then in “Local” folder I can’t find
> “Programs” folder,but it says it downloaded in “Programs”.So can you help
> me.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regex on a Dictionary

2018-02-15 Thread Andre Müller
Hello,

this question also came up there:
https://python-forum.io/Thread-Working-with-Dict-Object

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


Re: Old format with %

2018-02-15 Thread Andre Müller
It can be escaped: "test %d %%" % 7

Terry Reedy  schrieb am Mi., 14. Feb. 2018 um 20:53 Uhr:

> On 2/14/2018 7:54 AM, ast wrote:
> > Le 14/02/2018 à 13:46, ast a écrit :
> >> Hello
> >>
> >> It seems that caracter % can't be escaped
> >>
> >>  >>>"test %d %" % 7
> >> ValueError: incomplete format
> >>
> >>  >>>"test %d \%" % 7
> >> ValueError: incomplete format
> >>
> >>  >>>"test %d" % 7 + "%"
> >> 'test 7%'  # OK
> >>
> >> But is there a way to escape a % ?
> >>
> >> thx
> >
> > Found, double % to escape it
> >
> >  >>>"test %d%%" % 7
> > 'test 7%'
>
> Same with { and } in new format and f strings.
>  >>> a = 3
>  >>> f'{{x:{a}}}'
> '{x:3}'
>
> --
> Terry Jan Reedy
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why no '|' operator for dict?

2018-02-05 Thread Andre Müller
You can use keyword-argument unpacking in a dict-constructor.
Values of duplicate keys are overwritten from left to right. The last wins.

>>> dict1 = {'foo': 13, 'bar': 42}
>>> dict2 = {'foo': 42, 'hello': 'world'}

>>> {**dict1, **dict2}
{'bar': 42, 'foo': 42, 'hello': 'world'}

{**dict2, **dict1}
{'bar': 42, 'foo': 13, 'hello': 'world'}

You can make a Class for this task, if you need it very often:

class UDict(dict):
def __or__(self, other):
if not isinstance(other, (self.__class__, dict)):
raise ValueError('Is not a dict!')
return {**self, **other}
__ror__ = __or__

>>> UDict({'foo': 1, 'bar': 1337}) | UDict({'bar': 43})
{'bar': 43, 'foo': 1}
>>> UDict({'foo': 1, 'bar': 1337}) | {'bar': 43}
{'bar': 43, 'foo': 1}
>>> {'foo':42} | UDict({'foo': 1, 'bar': 1337})
{'bar': 1337, 'foo': 42}


Greetings
Andre

Steven D'Aprano  schrieb am Mo., 5.
Feb. 2018 um 11:03 Uhr:

> On Mon, 05 Feb 2018 01:14:53 -0700, Ian Kelly wrote:
>
> > On Mon, Feb 5, 2018 at 12:35 AM, Frank Millman 
> > wrote:
> >> So I have 2 questions -
> >>
> >> 1. Is there any particular reason why '|' is not supported?
> >
> > '|' is the set union operation, roughly equivalent to the set.union
> > method. Dicts don't have a union operation. If they did, and the same
> > key were found in both sets, what would be the value of that key in the
> > union?
>
> Obviously it should be a quantum superposition of the two values, which
> remains uncertain until such time as you actually print the value and
> observe it.
>
>
>
>
> --
> Steve
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Regular expression

2017-07-26 Thread Andre Müller
fname = 'first-324-True-rms-kjhg-Meterc639.html'

# with string manipulation
stem, suffix = fname.rsplit('.', 1)
print(stem[-4:])

# oo-style with str manipulation
import pathlib
path = pathlib.Path(fname)
print(path.stem[-4:])
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pyserial and end-of-line specification

2017-07-15 Thread Andre Müller
Just take a look into the documentation:
https://docs.python.org/3/library/io.html#io.TextIOWrapper

And in the example of Pyserial:
http://pyserial.readthedocs.io/en/latest/shortintro.html#eol

I think it shold be:
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser),
newline='yourline_ending')

But the documentation of Pytho says:
Warning BufferedRWPair does not attempt to synchronize accesses to its
underlying raw streams. You should not pass it the same object as reader
and writer; use BufferedRandom instead.


Maybe you should also try:

sio = io.TextIOWrapper(io.BufferedRandom(ser), newline='yourline_ending')

If it's readonly:
sio = io.TextIOWrapper(io.BufferedReader(ser), newline='yourline_ending')


I never tried it, but your question leads me to take a look into this cool
features of the io module.

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


Re: why are these 2 fucking clowns in here ?

2017-06-30 Thread Andre Müller
Just don't read it. Calm down.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A Good Tutorial on Python Decorators

2017-06-27 Thread Andre Müller
Activate JavaScript, then you can see the content.
I had the same problem.

Peter Pearson  schrieb am Di., 27. Juni 2017 um
18:35 Uhr:

> On Tue, 27 Jun 2017 15:10:53 + (UTC), Saurabh Chaturvedi wrote:
> > https://opensource.google.com/projects/py-decorators-tutorial
>
> "No Results found."
>
> --
> To email me, substitute nowhere->runbox, invalid->com.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "Python launcher" required to run *.py scripts on Windows?

2017-06-27 Thread Andre Müller
Double Post:
https://python-forum.io/Thread-Python-launcher-required-to-run-py-scripts-on-Windows

Pleas don't do this. It's not a nice behavior.

Thanks.

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


Re: os.walk the apostrophe and unicode

2017-06-24 Thread Andre Müller
Can os.fsencode and os.fsdecode help? I've seen it somewhere.
I've never used it.

To fix encodings, sometimes I use the module ftfy

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


Re: Standard lib version of something like enumerate() that takes a max count iteration parameter?

2017-06-16 Thread Andre Müller
Am 15.06.2017 um 07:09 schrieb Jussi Piitulainen:
> Andre Müller writes:
>
>> I'm a fan of infinite sequences. Try out itertools.islice.
>> You should not underestimate this very important module.
>>
>> Please read also the documentation:
>> https://docs.python.org/3.6/library/itertools.html
>>
>> from itertools import islice
>>
>> iterable = range(100)
>> # since Python 3 range is a lazy evaluated object
>> # using this just as a dummy
>> # if you're using legacy Python (2.x), then use the xrange function for it
>> # or you'll get a memory error
>>
>> max_count = 10
>> step = 1
>>
>> for i, element in enumerate(islice(iterable, 0, max_count, step), start=1):
>> print(i, element)
> I like to test this kind of thing with iter("abracadabra") and look at
> the remaining elements, just to be sure that they are still there.
>
> from itertools import islice
>
> s = iter("abracadabra")
> for i, element in enumerate(islice(s, 3)):
> print(i, element)
>
> print(''.join(s))
>
> Prints this:
>
> 0 a
> 1 b
> 2 r
> acadabra
>
> One can do a similar check with iter(range(1000)). The range object
> itself does not change when its elements are accessed.

Very interesting. Normally this should not work.
The behavior is unexpected. So you taught me, what can happen.

Thank You :-)

Normally you don't see very often iter(). If you've short sequences
which are str,
you can just use index access. My example is for something, which is
bigger than memory.
Otherwise you've sometimes objects which doesn't support index access
like sets or generators.
Then you can use this nifty trick.

Instead of using:

s = iter('abracadabra') # no direct access to the str object

You should use:

s = 'abracadabra' # direct access to object
iterator = iter(s) # makes an iterator which is accessing s. The str object 
does not change.
# s is still 'abracadabra'

# also you can make more than one iterator of the same object
iterator2 = iter(s)
iterator3 = iter(s)
iterator4 = iter(s)
# they only rely on s, but they are independent iterators
# s won't change

Another trick is:

# incomplete chunks are left out
list(zip(*[iter(s)]*4))
# -> [('a', 'b', 'r', 'a'), ('c', 'a', 'd', 'a')]

# incomplete chunks will have None in the list
list(itertools.zip_longest(*[iter(s)]*4))
# -> [('a', 'b', 'r', 'a'), ('c', 'a', 'd', 'a'), ('b', 'r', 'a', None)]

# to impress your friends you can do
for chunk in itertools.zip_longest(*[iter(s)]*4):
chunked_str = ''.join(c for c in chunk if c) # generator expression
inside join with condition
print(chunked_str)

It took long time for me to understand this.
Someone has written this nifty tick in the python irc channel.

You should create every time a new iterator with iter, when iterating
over something again.
In your example you're iterating twice over the same iterator.

When you're using for example a for loop, it creates internally an
iterator of your object, if it's supported.
It gets element by element and assigns it to one_char.

# creates iterator for s and iterates over it
for one_char in s:
print(one_char)

# creates again a new iterator for s and iterates over it
for one_char in s:
print(one_char)





signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you use Python 3.5 and Python 3.6 in production

2017-06-14 Thread Andre Müller
Hi,
I'm using Arch Linux. There is currently Python 3.6 the standard
interpreter.
But I think it's not good to use this in production.

Hm, maybe pyenv can be an distribution independent solution:
https://github.com/pyenv/pyenv
If you're using pyenv, then you'll have some build dependencies.

One time I've used a Debian repository to install Python 3.6 somewhere (can
not remind where).
But then you rely on the user, who is managing the repository.

I often build my own Python version. If you're willing to do this, you can
build your own packages
on your own repository. Then you can install this version on your
production without having there the
whole build dependencies. But this is additional work.

Amirouche Boubekki  schrieb am Do., 15. Juni
2017 um 01:47 Uhr:

> Héllo,
>
>
> I'd like to use Python 3.5 or Python 3.6 in production but avoid the use of
> pip and virtualenv.
>
> Is there a solution based on a popular GNU/Linux distribution that allows
> to keep up with the release of Python 3.x and various other highly prolific
> project but still young like aiohttp?
>
> What I am looking for is the ability to have reproducible builds in the
> form of lxc templates (or maybe somekind of docker magic) but without the
> need to maintain another package repository.
>
> I hope my question is clear.
>
> Thanks in advance!
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Converting epoch to string in format yyyy-mm-dd, or maybe it is not necessary

2017-06-14 Thread Andre Müller
I'm not familar with pandas.

If you look on stackoverfolow you'll find this solution:

df.epoch = pd.to_datetime(df.epoch)
https://stackoverflow.com/questions/17134716/convert-dataframe-column-type-from-string-to-datetime

But in this case, it's not a plain string, then it's a datetime object.

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


Re: API Help

2017-06-14 Thread Andre Müller
Am 14.06.2017 um 22:33 schrieb Bradley Cooper:
> I am working with an API and I get a return response in this format.
>
>  
> [{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT-1-US","quantityAvailable":0.0},{"warehouseCode":"KY-1-US","quantityAvailable":0.0},{"warehouseCode":"TX-1-US","quantityAvailable":14.0},{"warehouseCode":"CA-1-US","quantityAvailable":4.0},{"warehouseCode":"AB-1-CA","quantityAvailable":1.0},{"warehouseCode":"WA-1-US","quantityAvailable":0.0},{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]
>
> What is the best way to read through the data?
>

Your data looks like Json.
First use the _json_ module to convert the _string_ into a _Python data
structure_.
Then you can iterate over it. My example is a nested loop. Maybe
you've more than one element inside the list.


import json

# the string looks like json
JSON_DATA = """[
{"itemNumber":"75-5044","inventory": [
{"warehouseCode":"UT-1-US","quantityAvailable":0.0},
{"warehouseCode":"KY-1-US","quantityAvailable":0.0},
{"warehouseCode":"TX-1-US","quantityAvailable":14.0},
{"warehouseCode":"CA-1-US","quantityAvailable":4.0},
{"warehouseCode":"AB-1-CA","quantityAvailable":1.0},
{"warehouseCode":"WA-1-US","quantityAvailable":0.0},
{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}
]
}
]"""


# converting the json string to a Python data structure
inventory = json.loads(JSON_DATA)

# representation in Python
#[{'inventory': [{'quantityAvailable': 0.0, 'warehouseCode': 'UT-1-US'},
   #{'quantityAvailable': 0.0, 'warehouseCode': 'KY-1-US'},
   #{'quantityAvailable': 14.0, 'warehouseCode': 'TX-1-US'},
   #{'quantityAvailable': 4.0, 'warehouseCode': 'CA-1-US'},
   #{'quantityAvailable': 1.0, 'warehouseCode': 'AB-1-CA'},
   #{'quantityAvailable': 0.0, 'warehouseCode': 'WA-1-US'},
   #{'quantityAvailable': 0.0, 'warehouseCode': 'PO-1-CA'}],
  #'itemNumber': '75-5044'}]


# the interesting part
for items in inventory:
# get the elements in from the list
# the elements are dicts, in this case exactly one dict
print('itemNumber:', i['itemNumber'])
# nested loop iterating over the values of the key 'inventory'
for item in items['inventory']:
# the value is dict
code, qty = item['warehouseCode'],item['quantityAvailable']
print('warehouseCode:', code, 'quantityAvailable', qty)


# Output
#itemNumber: 75-5044
#warehouseCode: UT-1-US quantityAvailable 0.0
#warehouseCode: KY-1-US quantityAvailable 0.0
#warehouseCode: TX-1-US quantityAvailable 14.0
#warehouseCode: CA-1-US quantityAvailable 4.0
#warehouseCode: AB-1-CA quantityAvailable 1.0
#warehouseCode: WA-1-US quantityAvailable 0.0
#warehouseCode: PO-1-CA quantityAvailable 0.0


Greetings
Andre


signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Standard lib version of something like enumerate() that takes a max count iteration parameter?

2017-06-14 Thread Andre Müller
I'm a fan of infinite sequences. Try out itertools.islice.
You should not underestimate this very important module.

Please read also the documentation:
https://docs.python.org/3.6/library/itertools.html

from itertools import islice

iterable = range(100)
# since Python 3 range is a lazy evaluated object
# using this just as a dummy
# if you're using legacy Python (2.x), then use the xrange function for it
# or you'll get a memory error

max_count = 10
step = 1

for i, element in enumerate(islice(iterable, 0, max_count, step), start=1):
print(i, element)


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


Re: Hello from a super noob!

2017-06-08 Thread Andre Müller
Hello,

you can refactor your code a little bit and learn more about exceptions:

def get_numbers():
first = None
second = None
while True:
try:
if first is None:
first = int(input('Enter your first number: '))
if second is None:
second = int(input('Enter your second number: '))
except ValueError:
print('You have to enter a number')
continue
else:
return first, second


Am 08.06.2017 um 01:56 schrieb CB:
> Hi everyone,
> I am taking a python class and I'm stuck in an exercise.
>
> what am i doing wrong? Can anyone try to run it? Thanks so much! 
>
> #Description:Input validation and while loops.
>
>
> import random
> def main(): #main function need in all programs for automated testing
> 
>
> #your program goes here
> 
> print()
>
>
>
> 
> print("This program will help us practice input validation and while 
> loops.")
> print("The user will be asked to enter two numbers which will both be 
> validated. ")
> print("The sum of the numbers will then be displayed in a complex print 
> statement ")
> print("and the user will be asked if they would like to run the program 
> again."
> )
> print()
> print()
> 
> while True:
> FirstNumber = input ("Please enter the first number: ")
> if FirstNumber.isdigit ():
> FirstNumber = int(FirstNumber)
> break 
> else:
>   print ("Invalid response. Please enter a whole number. " )
> 
> while True:
> 
> SecondNumber = input ("Please enter the second number: " )
> if SecondNumber.isdigit():
> SecondNumber= int(SecondNumber)
>
> break
> else:
> print("Invalid response. Please enter a whole number." )
> 
> print()
> print (str(FirstNumber) + " + " + str(SecondNumber)+ " = " + 
> str(FirstNumber + SecondNumber))
> print()
> 
> while True:
> 
> ans= input('Would you like to run the program again (Y/N) : ')
> if ans== 'Y' or ans== 'N':
> break
>
> else:
> print(" lnvalid response. Please answer with 'Y' or 'N' ")
>
> if ans== 'N':
> break
>   
>




signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Referring to a module by a string without using eval()

2017-05-17 Thread Andre Müller
Peter Otten <__pete...@web.de> schrieb am Mi., 17. Mai 2017 um 09:31 Uhr:

> jeanbigbo...@gmail.com wrote:
>
> > I am trying to write some recursive code to explore the methods, classes,
> > functions, builtins, etc. of a package all the way down the hierarchy.
>
> > 2) I ultimately need to create inputs to explore_pkg programmatically en
> > route to a recursively called function.  The only way I can think of is
> to
> > use strings.  But, passing a string such as 'np.random' into explore_pkg
> > correctly returns the methods/... associated with the string and not the
> > module np.random
> >
> > e.g. explore_pkg('np.random') will NOT do what I want
> >
> > explore_pkg(eval('np.random')) does work but I understand eval is
> > dangerous and not to be trifled with.
>

Hello,
with a Class you can do it also.

import os

class Module:
def __init__(self, module):
self._name = module.__name__
print('Got module', self._name)
self._file = module.__file__ if hasattr(module, '__file__') else
'(built-in)'
self._module = module
def __repr__(self):
return "".format(self._name, self._file)
def __getattr__(self, key):
ret = getattr(self._module, key)
if isinstance(ret, types.ModuleType):
print('Attribute {} is in the module {}'.format(key,
self._name))
return Module(ret)
else:
print('Attribute {} is not a module. It\'s a {}'.format(key,
type(ret)))
return ret
def __getitem__(self, key):
return self.__getattr__(key)



os_wrapped = Module(os)

sub1 = 'path'
sub2 = 'sys'
sub3 = 'version'

value = os_wrapped[sub1][sub2][sub3]
print(value)

Maybe this code breaks other stuff. Also error handling is not present.

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


Re: Practice Python

2017-05-10 Thread Andre Müller


Am 10.05.2017 um 14:18 schrieb Chris Angelico:
> On Wed, May 10, 2017 at 10:11 PM, Andre Müller <gbs.dead...@gmail.com> wrote:
>> 1.) a short example for Python 3, but not exactly what they want.
>>
>> def square(numbers):
>> yield from sorted(n**2 for n in numbers)
>>
>> numberlist = [99, 4, 3, 5, 6, 7, 0]
>> result = list(square(numberlist))
> If you're going to use sorted(), why not simply return the list
> directly? This unnecessarily iterates through the list and builds a
> new one.
>
> ChrisA
You're right.
This can handle infinite sequences:

def square(numbers):
yield from (n**2 for n in numbers)


My example before can't do this.
Sorted consumes the whole list, there is no benefit.

*Ontopic*
Make a new empty list and iterate over your input_list,
do inside the loop the math operation and
append the result to the new list. Return the new list.

Hint1: The text above is longer as the resulting Code.
Hint2: Write this as a function (reusable code)
Hint3: Write this as a list comprehension.


Greetings
Andre


signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice Python

2017-05-10 Thread Andre Müller
Hello,

1.) a short example for Python 3, but not exactly what they want.

def square(numbers):
yield from sorted(n**2 for n in numbers)

numberlist = [99, 4, 3, 5, 6, 7, 0]
result = list(square(numberlist))

To solve this tutorial, you need a different way.
I'm just showing how sexy Python 3 is ;-)
Python 2.7 feels old... it is old. Please learn Python 3.

Greetings
Andre

Am 08.05.2017 um 08:52 schrieb gyrhgyrh...@gmail.com:
> Python - Exercise 5
> 1. Write a function that gets a list (list) of numbers. The function returns 
> a new list of ordered square numbers from the smallest to grow.
> For example, for the list [2, 4, 5, 3, 1] the function returns
> [25, 16, 9, 4, 1].
>
> 2. Write a function that receives a list (list) and a number. The function 
> returns the number of times the number appears in the list.
> For example, for list [2, 4, 2, 3, 2] and number 2 will return 3 because 
> number 2 is listed 3 times.
>
> The answers here:
>
> https://www.youtube.com/watch?v=nwHPM9WNyw8=36s




signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Bigotry and hate speech on the python mailing list

2017-04-18 Thread Andre Müller
Hello list,

Why are you fighting against symptoms?
Just to say: "Hate Speech is not allowed in this list and is bad",
doesn't solve the problem.

Humans from USA should think about it, why the whole world hates them.
Hm, what could be the cause?

You should think about the behavior of your government and your own
reactions.
The hate against people from USA has a cause and you can prove it with
your own history.
But Germany and many other countries are also supporting the USA...

Stopping war against other countries should be the first step to reduce
the hate.
You're fucked up about politics, war and hate? Then just make a new
constitution.


Greetings
Andre Müller




signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: write arrays to disk

2017-04-17 Thread Andre Müller
Hi,

there are many possible solutions.

You'll need a serialiser to convert the Python object into bytes.
If you wan't to access the data from other applications, you can use json,
xml or other well known formats. Json and XML is in the Python standard
library.
You can also use a database.

As json:
arr = [1, 2, 3, 4]
with open('array.json') as fd:
json.dump(arr, fd)

with open('array.json') as fd:
arr = json.load(fd)

With a bytearray:
arr = bytearray([1, 2, 3, 4])
with open('ba.bin', 'wb') as fd:
fd.write(arr)

with open('ba.bin', 'rb') as fd:
arr = bytearray(fd.read())

Another example with a numpy array:
arr = numpy.array([1, 2, 3, 4], dtype=numpy.int)
with open('array.bin', 'wb') as fd:
arr.tofile(fd)

with open('array.bin', 'rb') as fd:
arr = numpy.fromfile(fd, dtype=numpy.int)

What you should not do:

arr = [1, 2, 3, 4]
with open('plain.txt', 'wt') as fd:
fd.write(repr(arr))

with open('plain.txt') as fd:
arr = eval(fd.read())

If you need to store more data, you should think about a database.

Greetings
Andre

 schrieb am So., 16. Apr. 2017 um 14:29 Uhr:

> Hi,
>
> I'm new on Python software. I would like to write on disk arrays in
> binary or ascii format. Can someone please help me?
>
> Thanks,
>
> Conrado
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Merging multiple sorted sequences.

2017-04-17 Thread Andre Müller
Hi,
when you have lists with different lengths and want to zip them, you should
look at itertools.zip_longest

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