Rule of order for dot operators?

2015-05-16 Thread C.D. Reimer

Greetings,

Noobie question regarding a single line of code that transforms a URL 
slug ("this-is-a-slug") into a title ("This Is A Slug").


title = slug.replace('-',' ').title()

This line also works if I switched the dot operators around.

title = slug.title().replace('-',' ')

I'm reading the first example as character replacement first and title 
capitalization second, and the second example as title capitalization 
first and character replacement second.


Does python perform the dot operators from left to right or according to 
a rule of order (i.e., multiplication/division before add/subtract)?


Thank you,

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


Re: Rule of order for dot operators?

2015-05-16 Thread C.D. Reimer

On 5/16/2015 12:40 PM, Thomas 'PointedEars' Lahn wrote:
However, for greater efficiency, in general you should call .replace() 
in such a way that the length of the string it operates on is 
minimized. For example, if feasible, always slice *before* .replace().


Slice was how I got the slug from the URL in the first place. :)

Thank you,

Chris Reimer

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


Re: Rule of order for dot operators?

2015-05-16 Thread C.D. Reimer

On 5/16/2015 12:34 PM, Peter Otten wrote:
You can find out yourself by using operations where the order does 
matter: "Test".upper().lower() 


I was wondering about that and couldn't think of an example off the top 
of my head.


Thank you,

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


Re: Rule of order for dot operators?

2015-05-17 Thread C.D. Reimer

On 5/17/2015 10:17 AM, Thomas 'PointedEars' Lahn wrote:

C.D. Reimer wrote:

Consider using a regular expression or the urllib object instead. See 
RFC 3986, Appendix B, and 
<https://docs.python.org/3/library/urllib.html>, respectively.


That wouldn't work for me. I'm in the process of converting a WordPress 
website into a static website.


I wrote a script that pulled the HTML content from the SQL file to save 
each post in a text file with the URL as the file name (i.e., 
"2015-01-01-this-is-a-slug.html"). That created 275 files in the source 
folder.


Since I'm using Grav CMS (http://getgrav.org/) for my static website, I 
wrote a script to get the file names from the source folder, slice each 
file name into their respective component (i.e., year, month, day, slug, 
and title from the slug), convert the HTML into Markdown, and copy the 
content into a file called item.md inside a new folder (i.e., 
20150101.this-is-a-slug) in the destination folder.


After I get done cleaning up 275 item.md files in a Markdown editor, 
I'll write another script to create an .htaccess file to forward old url 
(i.e., /2015/01/01/this-is-a-slug) to the new URL (i.e., 
/blog/this-is-a-slug).


Gotta love string manipulations. ;)

Thank you,

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


Re: Rule of order for dot operators?

2015-05-18 Thread C.D. Reimer

On 5/16/2015 6:45 PM, Steven D'Aprano wrote:

On Sun, 17 May 2015 05:40 am, Thomas 'PointedEars' Lahn wrote:


C.D. Reimer wrote:

Who?

Don't be a dick, Thomas. Lots of people use their initials. You use your
nickname as part of your sender address, why are you questioning somebody
for using their initials?


I used my initials to hide my online presence from the Real World(tm). If a 
hiring manager looks up my legal name on the Internet, he or she will find a 
bunch of Usenet postings when I was a SuSE Linux noob in the 1990's. The only 
online accounts I have under my legal name is a Yahoo email address and a 
LinkedIn profile. After working at one employer that allowed anything found on 
the Internet as ammo in the office politics, a blank online slate provides 
better protection from such nonsense.

Besides, I got called by my initials in school when the compact discs (CD) 
became popular. :)

As for my question, my 2007 Core Python Programming book (based on python 2.5) 
indexed the dot for search operations. Some code examples show a single call 
(i.e., object.method()) but not multiple calls (i.e., 
object.method().method()). Since I wasn't sure what I was looking for, an 
Internet search turned up nothing useful. Hence, IMHO, a noobie question.

Maybe I need a newer python book?

Thank you,

Chris Reimer

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


Re: What is considered an "advanced" topic in Python?

2015-05-30 Thread C.D. Reimer

On 5/29/2015 9:01 AM, Mike Driscoll wrote:

I've been asked on several occasions to write about intermediate or advanced topics in Python and I 
was wondering what the community considers to be "intermediate" or "advanced".


I'm trying my hand at Cython (http://cython.org/). I just know enough of 
the Python and C languages to understand the book, "Cython" by Kurt W. 
Smith, but trying to understand this on a deeper level by re-reading 
each chapter two or three times is enough to give me a headache.  Which 
is fine since I have no use for a programming book that I can breeze 
through. Then again, maybe this book wasn't the best book to learn 
Cython from.


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


Python Random vs. Cython C Rand for Dice Rolls

2015-06-07 Thread C.D. Reimer

Greetings,

I've revisited my misbegotten childhood by translating the programs from 
"BASIC Computer Games" by David H. Ahl into Python. This is mostly an 
exercise in unraveling spaghetti code with all those GOTO statements 
going all over the place. The dice program caught my attention in 
particular for a stripped down version in Python and Cython to test the 
random number generator functionality.


http://www.atariarchives.org/basicgames/showpage.php?page=57

Here are my scripts to roll a pair of dice 50,000,000 times (this number 
creates a noticeable delay on my 3GHz quad processor). The Python script 
uses random, the Cython script uses C rand. Besides the obvious speed 
difference, the results are quite different.


This is the Python script that takes ~197 seconds to complete.

import random, time

startTime = time.time()

f = [0] * 12

for i in range(5000):

a = random.randint(1,6)

b = random.randint(1,6)

f[(a + b) - 1] += 1

print "\nTOTAL SPOTS","\tNUMBER OF TIMES\n"

for i in range(1,12):

print ' ' + str(i + 1), '\t\t ', f[i]

print '\n', time.time() - startTime


This the Cython script that is imported into a test scripts similar to 
the Python script that takes ~1.6 seconds to complete.


cdef extern from "stdlib.h":

int c_libc_rand "rand"()

def roll(int x):

cdef:

int a, b, i

int f[12]

for i in range(x):

a = c_libc_rand() % 6 + 1

b = c_libc_rand() % 6 + 1

f[(a + b) - 1] += 1

return f

Here's the console output.

PS Z:\projects\programming\python\basic_games\fastdice> python slowdice.py

TOTAL SPOTS NUMBER OF TIMES

 21388086
 32776286
 44165556
 5869
 66940547
 78335864
 86945446
 95556470
 10   4169549
 11   2777972
 12   1388355

197.00669
PS Z:\projects\programming\python\basic_games\fastdice> python 
test_fastdice.py


TOTAL SPOTS NUMBER OF TIMES

 21389911
 3-2144697697
 44168249
 535008856
 66944907
 7512318212
 86945597
 9342017362
 10   4167485
 11   2775806
 12   1388465

1.63799977303

The Python random shows a uniform bell curve with low numbers at the 
ends and the peak in the middle, which is similar to the text in the 
book for the BASIC program. The Cython C rand is over all the place 
(especially with a negative number), which reminds me how bad the random 
number generator was on my 1MHz C64 in the day.


Is there something in the Cython code that I need to change and/or find 
a better C random number generator?


Thanks,

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


Re: Testing random

2015-06-07 Thread C.D. Reimer

On 6/7/2015 10:20 AM, Chris Angelico wrote:

A fourth
possibility is that mathematics works differently for him and for us,
which I suppose is possible; when I visited sci.math a while ago, I
found some people for whom everything I'd learned in grade school was
clearly wrong, and they were doing their best to enlighten the world
about the new truths of mathematics that they'd found.


I had the unfortunate luck of taking "Harvard Calculus" in college 
(circa 1995). The textbook was nothing but word problems from end to 
end. The goal was to get the students away from symbolic thinking of 
traditional calculus into thinking about real world problems that uses 
calculus. (Never mind that the majority of students don't use calculus 
after they get out school.) I bailed out after two weeks. Taking the 
class at 7:30AM probably didn't help.


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


Re: Python Random vs. Cython C Rand for Dice Rolls

2015-06-07 Thread C.D. Reimer

On 6/7/2015 10:23 AM, Chris Angelico wrote:

Before you go any further, can you just try this script, please, and
see how long it takes to run?

import random, time
startTime = time.time()
for i in range(5000):
 pass
print '\n', time.time() - startTime

I know, seems a stupid thing to try, right? But you're using Python 2,
as evidenced by the print statements, and that means that range() is
constructing a 50M element list. It's entirely possible that that's a
significant part of your time - allocating all that memory, populating
it, and then disposing of it at the end (maybe).


PS Z:\projects\programming\python\basic_games\fastdice> python 
test_random_time.py

4.84700012207


So... I'm not looking at the problem on the Python side in the correct way?

In particular, I'm using the wrong container type?

I was thinking "array" (like the Cython version) when I put the Python 
script together. I got an error message at one point about indexing the 
"list" that threw me off for a while. Since it looks like an array, 
walks like an array, and quack likes array, I fixed the indexing problem 
like an array. A list != array? :)


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


Re: Python Random vs. Cython C Rand for Dice Rolls

2015-06-07 Thread C.D. Reimer

On 6/7/2015 10:33 AM, Chris Angelico wrote:

The negative result is a strong indicator that you're not seeing the
results of rand() here. While there is a potential for bias (check out
RAND_MAX, and consider that there may be some small bias there;
although on most modern systems, RAND_MAX is going to be high enough
that the bias from modulo 6 won't be highly visible), it's much MUCH
more likely that you're looking at uninitialized memory.


Here's the revised Cython code.

cdef extern from "stdlib.h":

int c_libc_rand "rand"()

cdef int f[12]




def roll(int x):

cdef:

int a = 0, b = 0, i = 0

for i in range(x):

a = c_libc_rand() % 6 + 1

b = c_libc_rand() % 6 + 1



f[(a + b) - 1] += 1

return f


Here's the new console output.

PS Z:\projects\programming\python\basic_games\fastdice> python test_fastdice.py

TOTAL SPOTS NUMBER OF TIMES

 21389911

 3222

 44168248

 55553632

 66944907

 78334670

 86945597

 95553557

 10   4167485

 11   2775806

 12   1388465

1.65599989891


I had to put the array definition outside of the function declaration, 
where it's automatically initialized to zero in the global space. I 
tried to initialize the array from inside the function but Cython threw 
up errors, either the C declaration wasn't correct or unable to convert 
from C to Python when updating the array elements. I'll figure out that 
problem later. The new version works as expected.


Thanks,

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


Re: Python Random vs. Cython C Rand for Dice Rolls

2015-06-07 Thread C.D. Reimer

On 6/7/2015 11:33 AM, Steven D'Aprano wrote:

C rand is not even close to random. The technical term for it is "shite".


Looking through the BASIC book, I remembered all the tricks needed to 
get a half-way decent number generator on a 1MHz processor back in the 
day. Either the numbers start repeating after a while or get stuck on a 
particular number. That's one of the challenges of converting these old 
games from BASIC to Python. A lot of the stuff done in BASIC was meant 
to get around the hardware limitations of the early computers.


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


Re: XCode and Python

2015-06-11 Thread C.D. Reimer

On 6/11/2015 3:09 PM, Sebastian M Cheung via Python-list wrote:
Or I need to configure something in Xcode? 


Perhaps this link might help determine if the problem is with Xcode 
and/or Python.


http://stackoverflow.com/questions/5276967/python-in-xcode-6

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


Is there a utility to tally function calls from other files?

2015-06-13 Thread C.D. Reimer

Greetings,

I'm converting 101 BASIC games from an old book 
(http://www.atariarchives.org/basicgames/) into Python scripts. After a 
dozen conversions, I've created a helper file for common functions 
(i.e., pick_card(), replay_game() and roll_dice()). The functions for 
card and dice games are obvious candidates for the helper file, but 
other functions that might be one offs that shouldn't be included.


Is there utility that will take the function names from the helper file 
and scan the other files to tally up how many times a particular 
function got called?


Or do I need to write a script?

Thanks,

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


Re: Is there a utility to tally function calls from other files?

2015-06-13 Thread C.D. Reimer

On 6/13/2015 12:31 PM, Chris Angelico wrote:

Depending on your requirements, it could be anywhere from easy to
hard. Good luck:)


I don't have  grep on my Windows machine. Writing a script might be easier.

Each file has a import statement for the helper file:

from bg_helper import replay_game, roll_dice

I just need to grab the function names from the helper file, walk the 
directory, find the import line from each file, and parse each line for 
the function names to build the tally.


Thanks,

Chris R.

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


Re: Is there a utility to tally function calls from other files?

2015-06-13 Thread C.D. Reimer

On 6/13/2015 12:58 PM, Chris Angelico wrote:

Hmm, I think the Windows 'find' command can do the same sort of job.
Though it's not hard to grab a Windows port of grep and use that.
Should be easier than writing your own script.


Writing the script would be easier for me since I'll be cobbling 
together several scripts I've used before.


Thanks,

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


Re: Is there a utility to tally function calls from other files?

2015-06-13 Thread C.D. Reimer

On 6/13/2015 1:02 PM, Terry Reedy wrote:
If you have a normal Python installation, you do.  Idle's Find in 
Files is a grep function with a gui interface.


I have Notepad++ on Windows. The find function for that program does the 
same thing. If I have a working Mac, Text Wrangler does the same thing 
as well.


Thanks,

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


Re: Is there a utility to tally function calls from other files?

2015-06-13 Thread C.D. Reimer

On 6/13/2015 1:59 PM, Laura Creighton wrote:

Idle is written in pure python.  Steal from:
https://hg.python.org/cpython/file/74d182cf0187/Lib/idlelib/GrepDialog.py
if you do not have a copy locally.


I've been using Notepad++ (Windows) and TextWrangler (Mac) for over a 
decade now. Idle may be pure Python, but that's not enough for me to 
switch. :)


Thanks,

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


Re: Is there a utility to tally function calls from other files?

2015-06-13 Thread C.D. Reimer
Here's my code and output for the curious. I'm sure someone will come up 
with a five-line version. :)


import os, time

def main():

def_str = 'def '

line_limit = 5

call_tally = []

import_str = 'from bg_helper import '

path = 'scripts'

startTime = time.time()




# pull call names from helper file

with open(os.path.join(path, 'bg_helper.py')) as f:

for line in f:




search = line.find(def_str)




if search != -1:




call_tally.append([(line[len(def_str):].split('('))[0], 0])




call_tally.sort()




# walk through the scripts directory

fileList = next(os.walk(path))[2]

fileList.remove('bg_helper.py')

fileList.remove('bg_helper.pyc')




# check files for import statements

for filename in fileList:




i = 0




with open(os.path.join(path, filename)) as f:




for line in f:




if i < line_limit:




search = line.find(import_str)




if search != -1:

   


found = line[len(import_str):].strip('\n').split(', ')




found.sort()

 


for found in enumerate(found):




for tally in enumerate(call_tally):




if tally[1][0] == found[1]:




   tally[1][1] += 1




i += 1




else:




break

# print the results

print 'FUNCTION CALLS\t\tTALLY\tNOTES\n'




for tally in enumerate(call_tally):




print tally[1][0],'\t\t', tally[1][1],




if tally[1][1] == 0:




print '\t** NO CALLS **'




else:




print ''




print '\nEvaluated',len(fileList),'files in',




print '{0:.1g}'.format(time.time() - startTime),'seconds\n'






if __name__ == "__main__":

main()



FUNCTION CALLS  TALLY   NOTES

card_faces  1

pick_card   1

replay_game 3

roll_dice   2

slot_faces  0   ** NO CALLS **

Evaluated 10 files in 0.08 seconds

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


Do I need license to release the Python version of old BASIC games?

2015-06-21 Thread C.D. Reimer

Greetings,

I'm in the process of converting 101 old BASIC games into Python (see 
link below).


http://www.atariarchives.org/basicgames/

The short term goal is to learn the finer aspects of the Python language 
and reliving my misbegotten past on the Commodore 64. The long term goal 
is to use the completed project as part of a programming portfolio, as 
many of my past I.T. jobs have required no programming and my current 
job requires some PowerShell scripting (meh).


Many of these BASIC games floated around the university computer labs 
and DEC for years before being published in Creative Computing magazine 
and into book form in 1978. My Python scripts are faithful to the video 
output as listed in the book, but underlying code is vastly different 
than the BASIC code.


Do I need to release my scripts under a license? If so, which one?

Thanks,

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


Re: Do I need license to release the Python version of old BASIC games?

2015-06-21 Thread C.D. Reimer

On 6/21/2015 1:00 PM, Laura Creighton wrote:

In a message of Sun, 21 Jun 2015 12:32:46 -0700, "C.D. Reimer" writes:


Do I need to release my scripts under a license? If so, which one?

You should, because if you don't you could pop up some day and
assert copyright and sue the hell out of people who use your code,
which means that many people won't touch it until you license it.


I want to strike a right balance between respecting the 1987 copyright 
of the book, which much of the code was either in the public domain or 
submitted to Creative Computing magazine, and protecting my own code 
that uses the video output from the book. I'm leaning towards the MIT 
license as many of games were developed in university computer labs and 
freely shared among computer users.


For a copyright blast from the past, consider Bill Gate's open letter to 
hobbyists stealing Microsoft Basic in 1976.


https://en.wikipedia.org/wiki/Open_Letter_to_Hobbyists

Thanks,

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


Re: Do I need license to release the Python version of old BASIC games?

2015-06-21 Thread C.D. Reimer



On 6/21/2015 1:58 PM, Marko Rauhamaa wrote:

Converting BASIC games to Python results in derived works, which are
under the original copyright of the BASIC games.

 From the given link:

BASIC Computer Games is copyright © 1978 by David H. Ahl, and is
posted on www.atariarchives.org with permission. Do not redistribute,
mirror, or copy this online book.

So a license from David H. Ahl is required before publishing Python
translations.


The copyright applies to the book ("Do not redistribute, mirror, or copy 
this *online book*.") and any derivative work is based on the book. 
Using the video output from the BASIC games in the book could fall 
underneath the fair use provision, which allows me to use a small 
portion of the book without infringing on the copyright. I'm not 
publishing a book. I just want to put my code on a website as an 
educational example of what I did to convert a spaghetti language into a 
modern scripting language.


Thanks,

Chris R.


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


Re: Do I need license to release the Python version of old BASIC games?

2015-06-21 Thread C.D. Reimer

On 6/21/2015 3:02 PM, Marko Rauhamaa wrote:
As they say, tell that to the judge. 


More than likely, the original copyright owner can issue an DMCA take 
down notice and that will be end of that.


Thanks,

Chris R.


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


Best strategy for testing class and subclasses in pytest?

2015-08-22 Thread C.D. Reimer

Greetings,

I'm writing a chess engine to learn about Python classes and 
inheritance, and using pytest for the unit test. I've created a Piece 
class, which has 99% of the functionality for a chess piece, and 
subclass the other pieces -- Bishop, King, Knight, Pawn, Queen, Rook -- 
that will implement the move-specific functionality. I'm not sure what's 
the best strategy is for testing the class and subclasses.


I initially wrote unit tests for the class and subclasses (including 
tests for class-only functionality). That worked well until I started 
refactoring code and breaking the tests. Too much copy, paste and 
renaming for my taste.


I tried to create a separate class and/or module to import the common 
tests for each class and subclass. My attempts often ended in failure 
with the "RuntimeError: super(): no arguments" message. I couldn't find 
a working example on the Internet on how to do that. The pytest 
documentation is all over the place.


Is there a way to reuse tests in pytest?

Or should I test everything in the class and test only the implemented 
functionality in the subclasses?


Thank you,

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


Re: What Next After Python Basics

2014-07-13 Thread C.D. Reimer

On 7/13/2014 1:16 PM, Orochi wrote:

Hi,
I am beginner in Python
I have Completed Basic Python Course from Codecademy.com .
Now that I have a hands on the basics what is the next thing I should do.
I mean should I learn more or start a small Project(Any Ideas are Welcomed) or 
any Other suggestions.
Where to Start?

Thank You,
Orochi


My first project after barely learning the basics of Python was reading 
a spreadsheet with 600+ website URLs, taking a screenshot of each 
website, and building a HTML webpage to display the 600+ screenshots. If 
I was to do this manually (i.e., clicking and looking at each website), 
this would take two weeks of my spare time. By automating this task into 
a Python script (which took two weeks of my spare time), the script runs 
for two hours in the background and I take 15 minutes to glance at the 
HTML pages with screenshots. If I find something wrong with a particular 
screenshot, I can click on the website URL to investigate further.


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


What's the proper style for a library string function?

2014-07-19 Thread C.D. Reimer

Greetings,

I typically write a Python 2.7 string function in my library like this:

def getCompletedTime(start, end): return "Time completed:", str(end 
- start)


And called it like this:

print getCompletedTime(start, end)

Since every Python script I write is executed from the command line, I 
rewrote the string function like this:


def getCompletedTime(start, end): print "Time completed:", str(end 
- start)


And call it like this:

getCompletedTime(start, end)

The first version is what I'm familiar with having reluctantly learned 
Java at community college, which couldn't afford a Microsoft site 
license for Visual C++ and taught every class in Java. (The Linux 
instructor rebelled against this policy by teaching basic C/C++ and 
shell scripting in his classes.) I recently read an article that Python 
is replacing Java as a teaching language.


The second version is more straight forward but seems less readable 
(i.e., "print getCompletedTime(start, end)" vs. "getCompletedTime(start, 
end)") from the calling script.


Alternatively, I thought about rewriting the string function to accept 
an extra parameter to do either and default to the print statement.


def getCompletedTime(start, end, type = 'p'):
string = "Time completed: " + str(end - start)
if type == 'p':
print string
else:
return string

I'm curious as to what the proper Python style would be for this.

Thank you,

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


Re: Python and IDEs [was Re: Python 3 is killing Python]

2014-07-19 Thread C.D. Reimer

On 7/19/2014 12:28 AM, Steven D'Aprano wrote:

Earlier, I mentioned a considerable number of IDEs which are available
for Python, including:


I prefer to use Notepad++ (Windows) and TextWrangler (Mac). Text editors 
with code highlighting can get the job done as well, especially if the 
project is modest and doesn't require version control.


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


Re: What's the proper style for a library string function?

2014-07-19 Thread C.D. Reimer


On 7/19/2014 11:24 AM, Mark Lawrence wrote:

Besides that I wouldn't write the function on one line, the first.


I've seen code samples for simple functions with the definition and 
return statements written on one line.



Once you return your data you can do what you want with it.


Returning data from a function is probably the part I'm overlooking.


The third is really horrible in my book, YMMV.


That if/else version was something I've been thinking about doing and 
didn't it put it together until I wrote my email. If I couldn't write a 
better version, I wouldn't keep it myself.


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


Re: What's the proper style for a library string function?

2014-07-19 Thread C.D. Reimer


On 7/19/2014 11:56 AM, Ian Kelly wrote:

On Sat, Jul 19, 2014 at 12:24 PM, Mark Lawrence  wrote:


Also notice that I changed the function naming style from mixedCase to
lower_case_with_underscores. This is the style recommended for Python
by PEP 8, which you should read if you haven't already.
http://legacy.python.org/dev/peps/pep-0008/#naming-conventions


I love how that section of PEP 8 begins with: "The naming conventions of 
Python's library are a bit of a mess, so we'll never get this completely 
consistent -- nevertheless, here are the currently recommended naming 
standards."


My code is certainly in "a bit of a mess" as I'm still learning Python. 
Following the "Core Python Programming" book for the most part, and 
writing scripts to solve the problems that I'm having. I got an 
associate degree in computer programming but never mastered a 
programming language outside of web development. I'll need to unlearn 
all the bad habits I picked up with PHP over the years.


Chris Reimer


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


Re: What's the proper style for a library string function?

2014-07-19 Thread C.D. Reimer


On 7/19/2014 12:14 PM, Mark Lawrence wrote:


Is this what you intended?



I'm in the process of generalizing a library module from my first Python 
programming project to make it more accessible to other projects. The 
code I wrote for that project doesn't make sense anymore. As I 
generalize the library module, I'm also cleaning up the calling code 
from that project and other scripts.


The corrected version of the string function should be:

def format_completed_time(start, end):

 return "Time completed: " + str(end - start)

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


Re: Python and IDEs [was Re: Python 3 is killing Python]

2014-07-19 Thread C.D. Reimer

On 7/19/2014 5:41 PM, Tim Delaney wrote:
The main thing is that versioning should be automatic now - it's 
almost free, and the benefits are huge because even trivial scripts 
end up evolving.


I keep my modest Python scripts in a Dropbox directory and run a weekly 
Python script to zip up the Dropbox directory for safekeeping on the 
home file server and Microsoft OneDrive. If I really need a recent copy 
of a script, Time Machine on the Mac should have a copy from the Drop 
Box folder.


The only time I use version control is when I have a big project with 
many moving parts and/or I'm publishing software for other people to use.


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


Re: Python and IDEs [was Re: Python 3 is killing Python]

2014-07-19 Thread C.D. Reimer


On 7/19/2014 6:23 PM, Steven D'Aprano wrote:
I haven't used Python on Windows much, but when I did use it, I found 
the standard Python interactive interpreter running under cmd.exe to 
be bare- bones but usable for testing short snippets. If I recall 
correctly, it is missing any sort of command history or line editing 
other than backspace, which I guess it would have been painful to use 
for extensive interactive work, but when I started using Python on 
Linux the interactive interpreter had no readline support either so it 
was just like old times :-)


Windows PowerShell supports very basic Linux commands and has a command 
history. I'm always typing "ls" for a directory listing when I'm on a 
Windows machine. The regular command line would throw a DOS fit. 
PowerShell lets me get away with it.


http://en.wikipedia.org/wiki/Windows_PowerShell#Comparison_of_cmdlets_with_similar_commands

I prefer working on my vintage 2006 Black MacBook. Alas, the CPU fan is 
dying and MacBook shuts down after 15 minutes. I'm surprised at how well 
I was able to set up a equivalent programming environment on Windows.


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


Re: Python and IDEs [was Re: Python 3 is killing Python]

2014-07-19 Thread C.D. Reimer


On 7/19/2014 7:03 PM, TP wrote:
I would say that since PyCharm (https://www.jetbrains.com/pycharm/) 
now has a free Community Edition it is an even more notable IDE as the 
above two programs cost $.


PyCharm look really nice as an IDE. Thanks for the heads up.

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


Re: one to many (passing variables)

2014-07-25 Thread C.D. Reimer


On 7/24/2014 2:58 AM, Ben Finney wrote:

Here is an article on good API design; the principles apply to Python
http://blog.isnotworking.com/2007/05/api-design-guidelines.html>.
You know your API and its requirements better than we; see whether that
sheds any light on improvements to make.
Thank you for the link. I'm curious about one item mentioned in the 
article: "Avoid return values that Demand Exceptional Processing: return 
zero-length array or empty collection, not null"


Isn't a zero-length array, empty collection and null all the same thing?

Or does the "Demand Exceptional Processing" comes from testing to see if 
the object is empty versus being null?


And does this apply to Python?

Thank you,

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