Survey: improving the Python std lib docs

2017-05-12 Thread Steve D'Aprano
One of the more controversial aspects of the Python ecosystem is the Python
docs. Some people love them, and some people hate them and describe them as
horrible.

Here are a couple of suggestions for improving(?) the docs. What do you
think?

(They're not my ideas, the originated on Reddit.)


(1) Table of functions/classes at the start of each module doc

The docs for builtins starts with a table of built-in functions:

https://docs.python.org/3/library/functions.html


Docs for other modules should do similar, e.g. for the string module there
should be a table showing:

ascii_letters
ascii_lowercase
ascii_uppercase
capwords
digits
Formatter
hexdigits 
octdigits 
printable 
punctuation
Template
whitespace


which link to the detailed documentation for that object.

https://docs.python.org/3/library/string.html 


The statistics module shows something similar:

https://docs.python.org/3/library/statistics.html



(2) The PHP documentation allows you to search for a term by typing it into
the URL after the domain, e.g. to search for "split", go to:

http://php.net/split


If you try the same thing with the Python docs:

http://python.org/split

you get a 404. Suggestion: 404s should redirect and search the docs.




-- 
Steve
Emoji: a small, fuzzy, indistinct picture used to replace a clear and
perfectly comprehensible word.

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


Re: Survey: improving the Python std lib docs

2017-05-12 Thread Chris Angelico
On Fri, May 12, 2017 at 8:02 PM, Steve D'Aprano
 wrote:
> (2) The PHP documentation allows you to search for a term by typing it into
> the URL after the domain, e.g. to search for "split", go to:
>
> http://php.net/split
>
>
> If you try the same thing with the Python docs:
>
> http://python.org/split
>
> you get a 404. Suggestion: 404s should redirect and search the docs.

So long as we're talking about the existing search functionality, I'm
a big NO on this one. It's way too slow to be used as a general 404.

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


Re: Survey: improving the Python std lib docs

2017-05-12 Thread Dan Sommers
On Fri, 12 May 2017 21:14:01 +1000, Chris Angelico wrote:

> On Fri, May 12, 2017 at 8:02 PM, Steve D'Aprano
>  wrote:
>> (2) The PHP documentation allows you to search for a term by typing it into
>> the URL after the domain, e.g. to search for "split", go to:
>>
>> http://php.net/split
>>
>>
>> If you try the same thing with the Python docs:
>>
>> http://python.org/split
>>
>> you get a 404. Suggestion: 404s should redirect and search the docs.
> 
> So long as we're talking about the existing search functionality, I'm
> a big NO on this one. It's way too slow to be used as a general 404.

I agree with ChrisA.  That said, if part of the 404 page were a link to
such a search, that may be convenient.

python.org/split does not exist.

Would you like to _search the python documentation for split_?

(where the underscore-bracketed text would be a link to
https://docs.python.org/3/search.html?q=split).

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


EuroPython 2017 Keynote: Armin Ronacher

2017-05-12 Thread Alexander Hendorf
We are pleased to announce our next keynote speaker for 
EuroPython 2017: 

 * Armin Ronacher * 


About Armin Ronacher


Armin Ronacher has founded a number of Python open source projects. 
Most notably, he is the creator of Flask, 
a popular Python web microframework. He is an experienced speaker 
at developer conferences and runs a popular blog where he shares 
his thoughts on open source, software development, and Python. 

In 2014, he received the Python Software Foundation Community Service Award 
for his work in the Python Open Source community.
Armin cares about well designed systems and APIs. 
He is currently working on Sentry, an open source crash reporting tool.

The Keynote: A Python for Future Generations
---

A journey through the current Python interpreter, 
some of the effects of its leaky abstraction on the language design 
and how we could evolve the language to future proof it. 
Covers some practical and not so practical ideas based on 
experience in the JavaScript and Rust ecosystem.

Enjoy,
--
EuroPython 2017 Team
http://ep2017.europython.eu/
http://www.europython-society.org/

PS: Please forward or retweet to help us reach all interested parties:
https://twitter.com/europython/status/863018377798967296
Thanks.

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


Re: Survey: improving the Python std lib docs

2017-05-12 Thread jladasky
On Friday, May 12, 2017 at 3:02:58 AM UTC-7, Steve D'Aprano wrote:

> (1) Table of functions/classes at the start of each module doc
> 
> The docs for builtins starts with a table of built-in functions:
> 
> https://docs.python.org/3/library/functions.html
> 
> 
> Docs for other modules should do similar...

I agree with this suggestion.  I usually know what I want out of a module, but 
I don't know the exact name(s) of the relevant function(s).  Frequently, I find 
myself looking through the docs... and in parallel, I start a Python 
interpreter, type "import foo", and then "dir(foo)" to see everything that the 
module foo contains.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Survey: improving the Python std lib docs

2017-05-12 Thread Ethan Furman

On 05/12/2017 03:02 AM, Steve D'Aprano wrote:


Here are a couple of suggestions for improving(?) the docs. What do you
think?



(1) Table of functions/classes at the start of each module doc


I like this idea.  Even if I don't know the exact thing I am looking for I can 
usually get close from the names.

--
~Ethan~

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


Re: Out of memory while reading excel file

2017-05-12 Thread Pavol Lisy
On 5/11/17, Peter Otten <[email protected]> wrote:
> Mahmood Naderan via Python-list wrote:
>
>> Excuse me, I changed
>>
>> csv.writer(outstream)
>>
>> to
>>
>> csv.writer(outstream, delimiter =' ')
>>
>>
>> It puts space between cells and omits "" around some content.
>
> If your data doesn't contain any spaces that's fine. Otherwise you need a
> way to distinguish between space as a delimiter and space inside a field, e.
>
> g. by escaping it:
>
 w = csv.writer(sys.stdout, delimiter=" ", quoting=csv.QUOTE_NONE,
> escapechar="\\")
 w.writerow(["a", "b c"])
> a b\ c
> 8
>
>> However,
>> between two lines there is a new empty line. In other word, the first
>> line
>> is the first row of excel file. The second line is empty ("\n") and the
>> third line is the second row of the excel file.
>>
>> Any thought?
>
> In text mode Windows translates "\n" to b"\r\n" in the file. Python allows
> you to override that:
>
 help(open)
> Help on built-in function open in module io:
>
> open(...)
> open(file, mode='r', buffering=-1, encoding=None,
>  errors=None, newline=None, closefd=True, opener=None) -> file
> object
>
> 
>
> newline controls how universal newlines works (it only applies to text
> mode). It can be None, '', '\n', '\r', and '\r\n'.  It works as
> follows:
>
> 
>
> * On output, if newline is None, any '\n' characters written are
>   translated to the system default line separator, os.linesep. If
>   newline is '' or '\n', no translation takes place. If newline is any
>   of the other legal values, any '\n' characters written are translated
>   to the given string.
>
> So you need to specify newlines:
>
> with open(dest, "w", newline="") as outstream:
> ...
>

But lineterminator parameter (
https://docs.python.org/3.6/library/csv.html#csv.Dialect.lineterminator
) is by default \r\n on linux too!

b = io.StringIO()
w = csv.writer(b)
w.writerows([["a", "b c"], ['a', 'b,c']])
b.getvalue()  # 'a,b c\r\na,"b,c"\r\n'

b = io.StringIO()
w = csv.writer(b, lineterminator='\n')
w.writerows([["a", "b c"], ['a', 'b,c']])
b.getvalue()  # 'a,b c\na,"b,c"\n'

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


Re: Survey: improving the Python std lib docs

2017-05-12 Thread Chris Angelico
On Sat, May 13, 2017 at 4:05 AM,   wrote:
> On Friday, May 12, 2017 at 3:02:58 AM UTC-7, Steve D'Aprano wrote:
>
>> (1) Table of functions/classes at the start of each module doc
>>
>> The docs for builtins starts with a table of built-in functions:
>>
>> https://docs.python.org/3/library/functions.html
>>
>>
>> Docs for other modules should do similar...
>
> I agree with this suggestion.  I usually know what I want out of a module, 
> but I don't know the exact name(s) of the relevant function(s).  Frequently, 
> I find myself looking through the docs... and in parallel, I start a Python 
> interpreter, type "import foo", and then "dir(foo)" to see everything that 
> the module foo contains.
>

While I don't disagree with the docs suggestion, it's worth noting
that dir(foo) is a powerful feature, and part of what makes Python so
awesome. So don't be afraid to use it :)

TBH I'm +0.5 on the table; if it includes absolutely everything the
module offers, it'll be unworkably large on some modules, but if it
doesn't, how do you pick which are the "important" ones? Possibly this
is the right solution for most modules, but there'll be a few special
cases (eg argparse) that prefix it with "hey, check out this quick
start guide first".

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


Re: import docx error

2017-05-12 Thread johnshivjo
On Wednesday, May 10, 2017 at 12:48:36 PM UTC-4, RRS1 wrote:
> Hi,
> 
> 
> I am very new to Python, have only done simple things >>>print("hello 
> world") type things.  I've really been looking forward to using Python.  I 
> bought Two books, downloaded Python 3.6.1 (32 & 64) and each time I try this:
> 
> 
> >>> import docx
> 
> 
> I get errors. 
> 
> 
> Traceback (most recent call last):
> File "", line 1 in 
> ModuleNotFoundError: No module named docx
> 
> 
> I read a thread somewhere saying it wasn't needed to do  import docx  anymore 
> but if I try  doc = docx.document,  I again get an error.
> 
> 
> I'm using Window 7 (but it also happens on 10).  I've searched for online 
> help and seen nothing that I can follow, references to PIP are over my head.  
> It's very frustrating.  Can somebody help?
> 
> 
> Really appreciate it.
> 
> 
> Thanks
> 
> 
> -John

for windows open CMD and type: python -m pip install python-docx
you should import python-docx
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Out of memory while reading excel file

2017-05-12 Thread Peter Otten
Pavol Lisy wrote:

> On 5/11/17, Peter Otten <[email protected]> wrote:
>> Mahmood Naderan via Python-list wrote:

>>> between two lines there is a new empty line. In other word, the first
>>> line is the first row of excel file. The second line is empty ("\n") and
>>> the third line is the second row of the excel file.
>>>
>>> Any thought?
>>
>> In text mode Windows translates "\n" to b"\r\n" in the file. Python
>> allows you to override that:

>> So you need to specify newlines:
>>
>> with open(dest, "w", newline="") as outstream:
>> ...
>>
> 
> But lineterminator parameter (
> https://docs.python.org/3.6/library/csv.html#csv.Dialect.lineterminator
> ) is by default \r\n on linux too!
> 
> b = io.StringIO()
> w = csv.writer(b)
> w.writerows([["a", "b c"], ['a', 'b,c']])
> b.getvalue()  # 'a,b c\r\na,"b,c"\r\n'

I don't have a Windows system to test, but doesn't that mean that on Windows 

with open("tmp.csv", "w") as f:
csv.writer(f).writerows([["one"], ["two"]])
with open("tmp.csv", "rb") as f:
print(f.read())

would produce

b"one\r\r\ntwo\r\r\n"

? How is that avoided?

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


Re: Out of memory while reading excel file

2017-05-12 Thread eryk sun
On Fri, May 12, 2017 at 8:03 PM, Peter Otten <[email protected]> wrote:
> I don't have a Windows system to test, but doesn't that mean that on Windows
>
> with open("tmp.csv", "w") as f:
> csv.writer(f).writerows([["one"], ["two"]])
> with open("tmp.csv", "rb") as f:
> print(f.read())
>
> would produce
>
> b"one\r\r\ntwo\r\r\n"
>
> ? How is that avoided?

Python 3 doesn't use the platform's standard I/O implementation.
However, it tries to be consistent with the platform by using
os.linesep as the default for translating newlines. That's not
necessarily compatible with the csv module, so it requires disabling
newline translation by passing newline="" to open(). Otherwise it does
cause the problem that you suppose it would, which is documented:

https://docs.python.org/3/library/csv.html#csv.writer
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Out of memory while reading excel file

2017-05-12 Thread codewizard
On Thursday, May 11, 2017 at 5:01:57 AM UTC-4, Mahmood Naderan wrote:
> Excuse me, I changed 
> 
> csv.writer(outstream)
> 
> to 
> 
> csv.writer(outstream, delimiter =' ')
> 
> 
> It puts space between cells and omits "" around some content. However, 
> between two lines there is a new empty line. In other word, the first line is 
> the first row of excel file. The second line is empty ("\n") and the third 
> line is the second row of the excel file.
> 
> Any thought?
>  
> Regards,
> Mahmood

Try opening the destination file in the binary mode:

open(dest, 'wb')

I ran into extra newlines when using csv.writerows() recently.
Since the default mode for open() is text, I imagine you get
extra newlines, since both csv and file object are adding them.
Switching to binary mode fixed it for me.

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


Re: Need help on a project To :"Create a class called BankAccount with the following parameters "

2017-05-12 Thread saisurya . ssa
On Saturday, December 12, 2015 at 2:35:29 PM UTC+5:30, Harbey Leke wrote:
> Create a class called BankAccount
> 
> .Create a constructor that takes in an integer and assigns this to a 
> `balance` property.
> 
> .Create a method called `deposit` that takes in cash deposit amount and 
> updates the balance accordingly.
> 
> .Create a method called `withdraw` that takes in cash withdrawal amount and 
> updates the balance accordingly. if amount is greater than balance return 
> `"invalid transaction"`
> 

> .Create a subclass MinimumBalanceAccount of the BankAccount class
> 
> Please i need help on this i am a beginer into python programming.
> 
> 
> Also below is a test case given for this project 
> 
> 
> import unittest
> class AccountBalanceTestCases(unittest.TestCase):
>   def setUp(self):
> self.my_account = BankAccount(90)
> 
>   def test_balance(self):
> self.assertEqual(self.my_account.balance, 90, msg='Account Balance 
> Invalid')
> 
>   def test_deposit(self):
> self.my_account.deposit(90)
> self.assertEqual(self.my_account.balance, 180, msg='Deposit method 
> inaccurate')
> 
>   def test_withdraw(self):
> self.my_account.withdraw(40)
> self.assertEqual(self.my_account.balance, 50, msg='Withdraw method 
> inaccurate')
> 
>   def test_invalid_operation(self):
> self.assertEqual(self.my_account.withdraw(1000), "invalid transaction", 
> msg='Invalid transaction')
>   
>   def test_sub_class(self):
> self.assertTrue(issubclass(MinimumBalanceAccount, BankAccount), msg='No 
> true subclass of BankAccount')

hi guys can get a perfect code and i have this code 
import time


menu_list = ["O -open account"] 
menu_list =["l - load details"]
menu_list =["D- display details"]
menu_list =["A - Make deposit"]
menu_list =["W- Make withdraw",]
menu_list =["S - save"]
menu_list =["Q - quit"]





creation_list = ["Account owners full name:", "starting balance: $"]
current_informatioon =["N/A","N/A","N/A"]
save_path= 'bank_accounts/'
information/_file = "information/"
current_newbank_number = open(information_file + "bankid_txt","r")
idnumber = int (current_newbank_number.readline())
current_newbank_number.close()
current_file = open(information_file, "file_txt","r")
filenames = current_files.readline()
filenames=[line.strip() for line in filenames]
current_files.close()
def save():
global current_information
save_name = open(save_path + str(current_information[0]) + ".txt,'w")
for i in current_information:
save_name.wrtie(str(i)+ "\n"):

def open():
golbal idnumber,current_informatiom
file_information = []

if current_informatiom[] != "N/A":
save()
file_information.append(int(idnumber))
idnumber: +=1
print("type c at any point to abort creation")
for i in creation_list:
value = input("\t" + i)
if value.upper() == "C":
menu()
else:
file_information.append(value)
file_information.append(time.strftime("%d%r%y) + "+account opened- $" 
+file_information[2])
current_information = files_information
current_information = file_information
save_name = open(save_path + str(file_information [0]) + ".txt", 'w')
for i in file_informatio;
save_name.write(str(i) + "\n")

current_file- = pen(information_file+str("file.txt",'w')
filename.append(file_information[0])
for i in filenames:
current_files_.wirte(str(i] + "\n")
id_file = open(information_file + "bankid.txt","w")
id_file.write(idnumber)

def deposit():
amount ==int(input("how much would you like to to deposit?"))
current_information[2] = int(current_informatiom[2]) + amount
current_informatiom.append(time.strftime("%d/%r/%y) + "-deposit - $" + 
str(amount))

def withdraw():
amount ==int(input("how much would you like to to withdraw?"))
current_information[2] = int(cuurnt_informatiom[2]) - amount
current_informatiom.append(time.strftime("%d/%r/%y) + -deposit - $" + 
str(amount))

def quit():
if current_information[0] != "N/A":
quit()
def load():
global current_information
count = 0
if current_informatioon[0] != "N/A":
save()
print()
print("|t", '***file list**")\for i in file name:
count += 1
print (count,1)
if count==0:
print("File list is empty")

print("TYpe C to go back to the menu")
print("Which file woulf you like")
selection = input()
if selection.upper == 'C':
menu()
elif int(selectiom) > and int(selection) <= len (filenames):
load_file = open(save_path +str(filename[int(selection)-1])+".txt,'r')
load_info = load_file.readline()
current_information =[line.strip() for line in load info]
print(current_information)
else:
pass
def display ();
print ()
print("Account balance:$" +str(current_information[2]))
if len(current_information)> 
:
print("Account history:")
for i in range(3, len{current_informatiom)):
print(current_information[1])
else:
print("No account loaded")

def menu()
menu_ = True
while menu_:
if current_informatiom[0] != "N/A":
print()
print("current loaded accoint:")
print("coustomer number:", current_information[0])
print("coustomer name:",current_information[1]
print("coustomer balance: $" + str(current_inf

Re: Need help on a project To :"Create a class called BankAccount with the following parameters "

2017-05-12 Thread Jason Friedman
>
> menu_list = ["O -open account"]
> menu_list =["l - load details"]
> menu_list =["D- display details"]
> menu_list =["A - Make deposit"]
> menu_list =["W- Make withdraw",]
> menu_list =["S - save"]
> menu_list =["Q - quit"]
>
> command = input("command:")
> if command.upper() == "O":
> open_()
> elif(comman.upper() =="l":
> load_()
> elif(comman.upper() =="a":
> deposit_()
> elif(comman.upper() =="W":
> withdraw_()
> elif(comman.upper() =="s":
> save_()
> elif(comman.upper() =="q":
>

There's a lot of code there so I will comment only on the sections above.

The first section does not do what I think you want:  a list with 7
options.  It makes a list with one option, then overwrites it with a new
list with one option, and so on.  You want something like:
menu_list = [
"O - open account"
"L - load details"
"D - display details"
"A - Make deposit"
"W - Make withdraw",
"S - save"
"Q - quit"
]

The second section has mistyped "command".  You also added underscores to
your method names.  Further, some of your match strings are lowercase, and
you only want to compare the first letter anyway.  Try:
command = input("command:")
if   command.upper().startswith("O"):
open()
elif command.upper().startswith("L"):
load()
elif command.upper().startswith("A"):
deposit()
elif command.upper().startswith("W"):
withdraw()
elif command.upper().startswith("S"):
save()
elif command.upper().startswith("Q"):
quit()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Need help on a project To :"Create a class called BankAccount with the following parameters "

2017-05-12 Thread Jason Friedman
>
>
>> The first section does not do what I think you want:  a list with 7
> options.  It makes a list with one option, then overwrites it with a new
> list with one option, and so on.  You want something like:
> menu_list = [
> "O - open account"
> "L - load details"
> "D - display details"
> "A - Make deposit"
> "W - Make withdraw",
> "S - save"
> "Q - quit"
> ]
>
>
D'oh!

menu_list = [
"O - open account",
"L - load details",
"D - display details",
"A - make deposit",
"W - make withdrawal",
"S - save",
"Q - quit",
]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Survey: improving the Python std lib docs

2017-05-12 Thread dieter
Steve D'Aprano  writes:
> One of the more controversial aspects of the Python ecosystem is the Python
> docs. Some people love them, and some people hate them and describe them as
> horrible.
>
> Here are a couple of suggestions for improving(?) the docs. What do you
> think?
>
> (They're not my ideas, the originated on Reddit.)
>
>
> (1) Table of functions/classes at the start of each module doc
>
> The docs for builtins starts with a table of built-in functions:
>
> https://docs.python.org/3/library/functions.html

>From my point of view, a good (manually maintained) documentation should not
contain information that can easily be obtained automatically.

Ideally, we should separate between overview information (explaining the
essential concepts and their relations) and detail information (list
of classes, functions, ...) with links between them. The detail information
is likely generated automatically from the source.

> ...
> (2) The PHP documentation allows you to search for a term by typing it into
> the URL after the domain, e.g. to search for "split", go to:
>
> http://php.net/split
>
>
> If you try the same thing with the Python docs:
>
> http://python.org/split
>
> you get a 404. Suggestion: 404s should redirect and search the docs.

Generate an "index" page from the complete documentation with links to
the term definitions. Then people who miss such a functionality can bookmark
that page.

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