Re: Target WSGI script cannot be loaded as Python module.

2018-05-23 Thread John Gordon
In <34bc9890-90c9-473d-bd26-3f62264aa...@googlegroups.com> 
=?UTF-8?B?zp3Or866zr/Pgg==?= <nikos.at.superh...@gmail.com> writes:

> I have both python installed in parallel.
> python2.7 and python3.6

> I have installed the modules as

> pip3.6 install bottle bottle-pymysql geopip2
> and they were installed successfully.

Is your web server using Python 2 or Python 3 to execute WSGI?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Detection of ultrasonic side channels in mobile devices with Python?

2018-02-28 Thread John Gordon
In <mailman.131.1519854895.2835.python-l...@python.org> Chris Angelico 
<ros...@gmail.com> writes:

> > Tell me how exactly ultrasonic side channels may activate remotely specific
> > neural pathways implicated in aggressivity and how to block theses specific
> > side channels from neuromodulating human behavior.

> Should be easy to find some whack-job newsgroups that would love to
> discuss that aspect of it.

Sounds like the plot to the latest Kingsman movie.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Where has the practice of sending screen shots as source code come from?

2018-01-29 Thread John Gordon
In <mailman.9.1517152018.2816.python-l...@python.org> Steven D'Aprano 
<steve+comp.lang.pyt...@pearwood.info> writes:

> I'm seeing this annoying practice more and more often. Even for trivial 
> pieces of text, a few lines, people post screenshots instead of copying 
> the code.

In some (perhaps rare) cases, a screenshot can provide useful independent
verification.

Such a screenshot recently helped me diagnose an issue in a stackoverflow
post.  A user was having trouble with some code that opens a file, and he
posted a screenshot of the code and a screenshot of a Windows File Explorer
window containing the desired file.  The File Explorer screenshot clearly
contained the desired file (named input.txt), and he was mystified as to
why the code was claiming the file did not exist.

The displayed filename in File Explorer was input.txt -- meaning that the
real filename was actually input.txt.txt, because File Explorer shows file
extensions as a separate column.

Without this screenshot, we would have had only the user's (incorrect)
assertion that the file existed, and no way to diagnose the true issue.

Granted, this was an environment issue and not a code issue, but I can
imagine situations where the same sort of thing could apply to code.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: has sourceforge exposed the dirty little secret ?

2018-01-05 Thread John Gordon
In <151517608506.368831.5093080329614058603@welt.netz> "Kim of K." 
<k...@korea.gov> writes:

> print(emo('now you see emos'))
> OF COURSE THIS SHIT DOES NOT WORK.

What device did you run this on?  Your average terminal window isn't
going to support emojis...

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: has sourceforge exposed the dirty little secret ?

2018-01-05 Thread John Gordon
In <15151695.348096.18338899180412170014@welt.netz> "Kim of K." 
<k...@korea.gov> writes:


> In other words: most sites like SF and github offer tons of crap.
> download and break is the overwhelming theme here.

> why is no one complaining ?

90% of everything is crap.  Why should software be any different?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: errors with json.loads

2017-09-20 Thread John Gordon
In <mailman.101.1505945630.2730.python-l...@python.org> john polo 
<jp...@mail.usf.edu> writes:

> JSONDecodeError: Expecting ':' delimiter: line 5 column 50 (char 161)

> ?json.loads says that the method is for deserializing "s", with "s" 
> being a string, bytes, or bytearray.

> In [24]: type(text)
> Out[24]: str

> So "text" seems to be a string. Why does json.loads return an error?

Because, although text is the right type, it does not contain a
valid json string.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Case-insensitive string equality

2017-08-31 Thread John Gordon
In <mailman.333.1504192626.2689.python-l...@python.org> Serhiy Storchaka 
<storch...@gmail.com> writes:

> > But when there is a common source of mistakes, we can help prevent
> > that mistake.

> How can you do this? I know only one way -- teaching and practicing.

Modify the environment so that the mistake simply can't happen (or at
least happens much less frequently.)

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Proposed new syntax

2017-08-10 Thread John Gordon
In <598c6d74$0$1588$c3e8da3$54964...@news.astraweb.com> Steve D'Aprano 
<steve+pyt...@pearwood.info> writes:

> What would you expect this syntax to return?

> [x + 1 for x in (0, 1, 2, 999, 3, 4) while x < 5]

[1, 2, 3]

> For comparison, what would you expect this to return? (Without actually
> trying it, thank you.)

> [x + 1 for x in (0, 1, 2, 999, 3, 4) if x < 5]

[1, 2, 3, 4, 5]

> How about these?

> [x + y for x in (0, 1, 2, 999, 3, 4) while x < 5 for y in (100, 200)]

[100, 101, 102, 200, 201, 202]

> [x + y for x in (0, 1, 2, 999, 3, 4) if x < 5 for y in (100, 200)]

[100, 101, 102, 103, 104, 200, 201, 202, 203, 204]

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: get value from list using widget

2017-07-05 Thread John Gordon
In <mailman.84.1499274961.2926.python-l...@python.org> 
jorge.conr...@cptec.inpe.br writes:

> Hi,

> I would like know dow can I select and get the value from a list of 
> values uisng widgets.

You haven't given us nearly enough detail to answer your question.

What do you mean by "widget"?  Do you mean HTML input elements such
as radio buttons or drop-down lists?  Or do you mean custom GUI widgets
such as you might create using the Tkinter package?

What do you mean by "select and get the value"?  Do you mean that you
want to present a widget to a user, that allows the user to select a
value?  Or do you actually mean that *you* want to select a value in
your code?

I could go on, but you get my point.  We need lots more information
before we can even begin to help you.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: how to add new tuple as key in dictionary?

2017-07-05 Thread John Gordon
In <344c23f8-f440-4c23-a5e6-9f93b0145...@googlegroups.com> Ho Yeung Lee 
<jobmatt...@gmail.com> writes:

> I find that list can not be key in dictionary
> then find tuple can be as key

> but when I add new tuple as key , got error in python 2.7

> groupkey = {(0,0): []}
> groupkey[tuple([0,3])] = groupkey[tuple([0,3])] + [[0,1]]

The right-hand side of your expression is rightly complaining that
groupkey[(0,3)] doesn't exist.

Would you expect to say

a = a + 1

When a doesn't exist?  Your code tries to do much the same thing.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Visit All URLs with selenium python

2017-04-13 Thread John Gordon
In <43f70312-83ba-457e-a83f-7b46e5d2a...@googlegroups.com> Nicole 
<bostanan...@gmail.com> writes:

> it just visit first url not all .. Can anybody help how to fix that..

Have you tried some basic debugging, for example printing p_links to
verify that it contains what you expected, and then printing each
url in the loop?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Quick questions about globals and database connections

2017-04-05 Thread John Gordon
In <oc308v$s18$2...@dont-email.me> DFS <nos...@dfs.com> writes:

> I have identical databases in sqlite and postgres.  I want to run the 
> same code against them, but am having a small issue.

> Current code below throws the dreaded:

> NameError: global name 'db' is not defined

> on line 12

> How do I fix it?  I want to keep dbconnect() as a separate function.

Instead of trying to make db global, dbconnect() can return the db object:

def dbconnect(dbtype):
if dbtype == "sqlite":
conn = sqlite3.connect(cstr)
elif dbtype == "postgres":
conn = psycopg2.connect(cstr)
return conn.cursor()

def updatedb(dbtype):
db = dbconnect(dbtype)
db.execute("DML code")
print "updated " + dbtype
'close connection

It would probably be even better to return conn, as that would allow
updatedb() to call conn.disconnect().

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: What's the neatest way of getting dictionary entries in a specified order?

2017-03-13 Thread John Gordon
In <mailman.241.1489242093.2612.python-l...@python.org> Michael Torrie 
<torr...@gmail.com> writes:

> The order of the displayed fields is usually something set by the GUI
> API when you create the table widget. At least in most toolkits I'm
> familiar with.  As well, when you add the row to the widget, you
> normally specify the fields (the data) individually, so I would think
> the order of the dict's fields does not matter since you'd manually
> specify each field's data.

The original example used a loop to get all of the dict fields and
add them to the GUI, instead of adding each field individually.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: How to add months to a date (datetime object)?

2017-02-06 Thread John Gordon
In <mailman.23.1486369390.2318.python-l...@python.org> "Deborah Swanson" 
<pyt...@deborahswanson.net> writes:

> bajimicb...@gmail.com wrote, on February 02, 2017 2:44 AM
> > 
> > for start of month to the beginning of next month
> > 
> > from datetime import timedelta
> > from dateutil.relativedelta import relativedelta
> > 
> > end_date = start_date + relativedelta(months=delta_period) + 
> > timedelta(days=-delta_period)

> Where do you define 'delta_period', and what is your question?

There is no question; it is an answer in response to the original
post asking how to add months to a datetime object.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Python3 using requests to grab HTTP Auth Data

2017-02-01 Thread John Gordon
In <efeq75fpf0...@mid.individual.net> Peter Pearson <pkpearson@nowhere.invalid> 
writes:

> > How can i ASK the user for http auth data and store them isntead of
> > giving them to the script?

> Maybe like this?

>   user = raw_input("User: ")
>   password = raw_input("Password: ")

If it doesn't need to be interactive, you could require that the user
supply a file in the current directory containing the username and
password.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Using python to start programs after logging in

2017-01-20 Thread John Gordon
In <878tq6hi0s@equus.decebal.nl> Cecil Westerhof <ce...@decebal.nl> writes:

> > I think using your window manager's built-in facilities for starting
> > programs would be better.  Why are you using Python instead?

> Because when you use the window managers builtin facilities then all
> programs will be started on the same virtual desktop and I want to
> start them on different ones.

The window manager doesn't allow you to specify a target desktop?  That
seems like a pretty heinous feature omission.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Using python to start programs after logging in

2017-01-19 Thread John Gordon
In <878tq6amvj@equus.decebal.nl> Cecil Westerhof <ce...@decebal.nl> writes:

> I am writing a python program to start the programs that need to be
> started after logging in.

> Is this a good way to do things, or could I do it in a better way?

I think using your window manager's built-in facilities for starting
programs would be better.  Why are you using Python instead?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: OT - "Soft" ESC key on the new MacBook Pro

2016-12-14 Thread John Gordon
In <ebbvoaf750...@mid.individual.net> Gregory Ewing 
<greg.ew...@canterbury.ac.nz> writes:

> Once you're in the clutches of Apple, there is no Escape.

Ha!

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Install Problem

2016-12-13 Thread John Gordon
In <mailman.55.1481661714.2322.python-l...@python.org> Rhesa Browning 
<rbrowni...@mmm.com> writes:

>I have been trying to install Python 3.5.2 onto my computer.  I have
>installed and uninstalled and resinstalled several times.  Every time I
>get an error message saying that the python35.dll doesn't exist on my
>computer so it can't open Python.  How can this problem be fixed?

When does the error occur?  During installation?  Or after installation
when you're trying to run a python program?

What version of Windows do you have?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread John Gordon
In <mailman.16.1481487105.2322.python-l...@python.org> "Juan C." 
<juan0christ...@gmail.com> writes:

> The instructor said that the right way to call a class attribute is to use
> 'Class.class_attr' notation, but on the web I found examples where people
> used 'self.class_attr' to call class attributes.

Class instances may override class attributes by creating local attributes
of the same name, in which case Class.class_attr and self.class_attr may
not be equal, so you'd have to use the correct one for your needs.

If you're sure that an instance does not override the class attribute,
then you can use whichever one you prefer.  self.class_attr may be more
convenient because you don't have to provide a specific class name.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: calling a program from Python batch file

2016-12-07 Thread John Gordon
In <f9d6e83d-d8e7-4245-a02f-906557263...@googlegroups.com> Karim Farokhnia 
<karim.farokh...@gmail.com> writes:

> Hi there,

> I am writing a batch file in Python. The batch file, in part, calls a
> program named "oq-console.bat" to run. Then once the program comes up
> (it looks like windows CMD), I need the batch file to type some commands
> to make it run (just like I would do it by myself).

If you need to start up a program, provide interactive input to it, and
perhaps examine its interactive output, then you want the "pexpect" module:

Pexpect is a pure Python module for spawning child applications;
controlling them; and responding to expected patterns in their output.
Pexpect allows your script to spawn a child application and control it
as if a human were typing commands.

https://pexpect.readthedocs.io/en/stable/

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-05 Thread John Gordon
In <o249l7$knc$1...@dont-email.me> DFS <nos...@dfs.com> writes:

> > Shells don't just repeat the characters you type, they interpret them.

> Yes, I see that now.  I still don't think bash/shell should alter the 
> input going to another program.

But that's one of the reasons *to* use a shell!

  ls *.cERROR No file named "*.c"
  ls > output   ERROR No file named ">"
  rm 'a file name'  ERROR No file named "'a file name'"
  cd ~/foo/bar  ERROR No file named "~/foo/bar"
  cat $HOME/file.txtERROR No file named '$HOME/file.txt' 
  vi $(grep -l foo *.txt)   ERROR No file named '$(grep -l foo *.txt)'

None of these commands would work if bash didn't "alter the input going to
another program".

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Error In querying Genderize.io. Can someone please help

2016-12-01 Thread John Gordon
In <af121073-5d8f-4fcd-933e-4f9ba8be2...@googlegroups.com> handa...@gmail.com 
writes:

> import requests
> import json
> names={'katty','Shean','Rajat'};
> for name in names:
> request_string="http://api.genderize.io/?"+name
> r=requests.get(request_string)
> result=json.loads(r.content)

You're using http: instead of https:, and you're using ?katty instead
of ?name=katty, and therefore the host does not recognize your request
as an API call and redirects you to the normal webpage.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Can json.dumps create multiple lines

2016-12-01 Thread John Gordon
In <87lgvz4no8@equus.decebal.nl> Cecil Westerhof <ce...@decebal.nl> writes:

> I started to use json.dumps to put things in a SQLite database. But I
> think it would be handy when it would be easy to change the values
> manually.

> When I have a value dummy which contains:
> ['An array', 'with several strings', 'as a demo']
> Then json.dumps(dummy) would generate:
> '["An array", "with several strings", "as a demo"]'
> I would prefer when it would generate:
> '[
>  "An array",
>  "with several strings",
>  "as a demo"
>  ]'

json.dumps() has an 'indent' keyword argument, but I believe it only
enables indenting of each whole element, not individual members of a list.

Perhaps something in the pprint module?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Python while loop

2016-11-30 Thread John Gordon
In <0c642381-4dd2-48c5-bb22-b38f2d5b2...@googlegroups.com> 
paul.garcia2...@gmail.com writes:

> Write a program which prints the sum of numbers from 1 to 101
> (1 and 101 are included) that are divisible by 5 (Use while loop)

> x=0
> count=0
> while x<=100:
> if x%5==0:
> count=count+x
> x=x+1
> print(count)
> 

> Question: How does python know what count means?

"count" is an english word meaning "how many things do I have?", but python
doesn't know that.  In python, "count" is just a name; you could have
called it "hamburger" and python would treat it just the same.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: MemoryError and Pickle

2016-11-21 Thread John Gordon
In <o0vvtm$1rpo$1...@gioia.aioe.org> Fillmore <fillmore_rem...@hotmail.com> 
writes:


> Question for experts: is there a way to refactor this so that data may 
> be filled/written/released as the scripts go and avoid the problem?
> code below.

That depends on how the data will be read.  Here is one way to do it:

fileObject = open(filename, "w")
for line in sys.stdin:
parts = line.strip().split("\t")
fileObject.write("ta: %s\n" % parts[0])
fileObject.write("wa: %s\n" % parts[1])
fileObject.write("ua: %s\n" % parts[2])
fileObject.close()

But this doesn't use pickle format, so your reader program would have to
be modified to read this format.  And you'll run into the same problem if
the reader expects to keep all the data in memory.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Parsing a single-level JSON file

2016-11-18 Thread John Gordon
In <o0nhh5$i5q$1...@reader2.panix.com> John Gordon <gor...@panix.com> writes:

> In <b9f6b419-7923-4c51-ba0d-c3bed68b0...@googlegroups.com> 
> mike.rei...@gmail.com writes:

> with open("json.dat", "r") as fp:
> data = json.load(fp)
> for item in data:
> if item['name'] == 'myField2':

Oops, that should be 'myField1' of course.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Parsing a single-level JSON file

2016-11-18 Thread John Gordon
In <b9f6b419-7923-4c51-ba0d-c3bed68b0...@googlegroups.com> 
mike.rei...@gmail.com writes:

> Im reading in a JSON file that looks like this
> ... snip ...
> Lets say I want to get the ID # of MyField1, how can I parse this with
> json lib? Theyre all on the same level, not sure how to target it to go
> to MyField1 and get "id" value. 

That data looks like a list of dictionaries:

import json

with open("json.dat", "r") as fp:
data = json.load(fp)
for item in data:
if item['name'] == 'myField2':
print item['id']

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


After import, some submodules are accessible and some aren't

2016-10-28 Thread John Gordon
After importing a module, I can access some of its submodules directly
but others require an explicit import of the submodule.

As an example, see ldap.dn and ldap.modlist:

% python
Python 2.7.8 (default, Aug  4 2016, 09:29:33)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ldap
>>> ldap.__version__
'2.4.19'
>>> ldap.modlist
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'module' object has no attribute 'modlist'
>>> ldap.dn

>>> import ldap.modlist
>>> ldap.modlist


Why the difference?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: exist loop by pressing esc

2016-10-24 Thread John Gordon
In <6e030fd0-93c1-4d23-8656-e06c411b6...@googlegroups.com> chris alindi 
<alindikri...@gmail.com> writes:

> simple while loop range(10) if user press esc exits loop

range() is typically used with for loops, not while loops.

what is your while condition?
what use is the range() value?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: How to handle errors?

2016-10-22 Thread John Gordon
In <d42dnwsq_pa11pffnz2dnuu7-bedn...@giganews.com> Wildman <best_...@yahoo.com> 
writes:

> > Another serious problem with using env in the hash-bang line is that you
> > cannot pass commandline options to the Python executable.

> Not true.  I made a test script with this code:

> #!/usr/bin/env python
> import sys
> print sys.argv

> Then I ran it:

> ~$ python test.py argument1 argument2
> ['test.py', 'argument1', 'argument2']

Options cannot be passed *on the hash-bang line*.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: How to handle errors?

2016-10-20 Thread John Gordon
In <8500044a-c8d1-43ad-91d9-e836d52bd...@googlegroups.com> SS 
<sami.st...@gmail.com> writes:

> I would like to be able to handle that error a bit better.  Any ideas?

Wrap the socket.gethostbyname() call in a try/except block.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Inplace shuffle function returns none

2016-10-18 Thread John Gordon
In <9d24f23c-b578-4029-ab80-f117599e2...@googlegroups.com> Sayth Renshaw 
<flebber.c...@gmail.com> writes:

> So why can't i assign the result slice to a variable b?

Because shuffle() modifies the list directly, and returns None.
It does NOT return the shuffled list.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Inplace shuffle function returns none

2016-10-18 Thread John Gordon
In <e1d9a80e-6c62-49ba-b946-695150a0d...@googlegroups.com> Sayth Renshaw 
<flebber.c...@gmail.com> writes:

> If shuffle is an "in place" function and returns none how do i obtain
> the values from it.

The values are still in the original object -- variable "a" in your example.

> from random import shuffle

> a = [1,2,3,4,5]
> b = shuffle(a)
> print(b[:3])

> For example here i just want to slice the first 3 numbers which should
> be shuffled. However you can't slice a noneType object that b becomes.

> So how do i get shuffle to give me my numbers?

    a = [1,2,3,4,5]
shuffle(a)
print(a[:3])

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Build desktop application using django

2016-10-17 Thread John Gordon
In <c9801e8b-2b8b-45a8-bcb0-27f775c1d...@googlegroups.com> 
ayuchitsalu...@gmail.com writes:

> Hello I want to build a desktop application which retrieves data from
> server and stores data on server. I have basic experience of python and
> I dont know how to build that thing.

The term "desktop application" generally means something which runs
locally on your computer, such as Microsoft Word or a game.

But Django is for building websites, not local applications.

So Django probably isn't what you want.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Free Python e-books from O'Reilly

2016-10-10 Thread John Gordon
In <e62e13fko7...@mid.individual.net> Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?= 
<martin.sch...@gmail.com> writes:

> http://www.oreilly.com/programming/free/

> Any of these good enough to bother getting? Yes, I know, they
> are for no pay but if not worth reading still a waste of time
> and memory space.

I downloaded several of them and noticed that they were all fairly short,
none more than 80 pages or so.  I suspect these books are somewhat lighter
fare than the typical O'Reilly tome.

Not necessarily a bad thing, but worth mentioning.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: xml parsing with lxml

2016-10-07 Thread John Gordon
In <622ea3b0-88b4-420b-89e0-9e7c6e866...@googlegroups.com> Doug OLeary 
<dkole...@olearycomputers.com> writes:

> >>> from lxml import etree
> >>> doc =3D etree.parse('config.xml')

> Now what?  For instance, how do I list the top level children of
> ?

root = doc.getroot()
for child in root:
print(child.tag)

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: how to append to list in list comprehension

2016-09-30 Thread John Gordon
In <534d5506-1810-4a79-ac8f-95a664d17...@googlegroups.com> Sayth Renshaw 
<flebber.c...@gmail.com> writes:

> I want to go threw and for each index error at [4] append a 0.

You want to append 0 if the list does not have at least 5 items?

> p = re.compile('\d+')
> fups = p.findall(nomattr['firstup'])
> [x[4] for x in fups if IndexError fups.append(0)]
> print(fups)

> Unsure why I cannot use append in this instance

Because that's incorrect syntax.

> how can I modify to acheive desired output?

for f in fups:
if len(f) < 5:
f.append(0)

Or, if you really want to use a list comprehension:

  [f.append(0) for f in fups if len(f) < 5]

However there's no reason to use a list comprehension here.  The whole
point of list comprehensions is to create a *new* list, which you don't
appear to need; you just need to modify the existing fups list.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Why does the insert after list function fail?

2016-09-22 Thread John Gordon
In <39ec91a8-eeae-489f-9237-9d9a481a8...@googlegroups.com> 
38016226...@gmail.com writes:

> A=["1","2","3"]
> print(list(map(float,A)).insert(0,1))

> I want to insert 1 at the head of the list but this gives me a surprise

insert() does not return anything; it modifies the existing list in-place.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: strings and ints consistency - isinstance

2016-09-21 Thread John Gordon
In <d58843f4-0636-43e6-aa16-465c97d89...@googlegroups.com> Sayth Renshaw 
<flebber.c...@gmail.com> writes:

> Trying to clarify why ints and strings arent treated the same.

Because they are not the same.

> You can get a valuerror from trying to cast a non-int to an int as in
> int(3.0) however you cannot do a non string with str(a).

Anything you type can be represented as a string*.  The same is
not true for integers.

* Okay, python 2.7 does have some issues with Unicode.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Requests for webbrowser module

2016-09-14 Thread John Gordon
In <mailman.196.1473872323.2411.python-l...@python.org> Jamie 
<ja9...@my.bristol.ac.uk> writes:

> I am not sure if this is an intended consequence but when using the 
> webbrowser module to open a new blank browser tab in chrome it opens it 
> in a new browser window instead of using the current window. Providing 

There is an internal setting within Chrome that controls whether new pages
are opened in a new tab or a new window.  Perhaps that is your issue?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: How to extend a tuple of tuples?

2016-09-12 Thread John Gordon
In <2349538.mvxudi8...@pointedears.de> Thomas 'PointedEars' Lahn 
<pointede...@web.de> writes:

> >> The obvious way does not work -
> >>
> >> a += (5, 6)
>  ^^
> > Right, because a tuple is immutable.

> How did you get that idea?  It has been mutated in the very statement that 
> you are quoting

No.  An entirely new tuple is created, and 'a' is rebound to it.  The
existing tuple is not mutated.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: memberof example using ldap

2016-09-12 Thread John Gordon
In <mailman.144.1473684507.2411.python-l...@python.org> Robert Clove 
<cloverob...@gmail.com> writes:

> Hi,
> I have to find if user is the member of a group, for this i am using the
> following query

> (&(objectClass=user)(sAMAccountName=yourUserName)
>   (memberof=CN=YourGroup,OU=Users,DC=YourDomain,DC=com))

> The above query doesn't work fine even if group doesn't exist,

> It always says that user is member of

The query returns a user who is not a member of the named group?
That's odd.

What is the search base and scope?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: ldap or active directory module

2016-09-09 Thread John Gordon
In <mailman.80.1473414113.2411.python-l...@python.org> Robert Clove 
<cloverob...@gmail.com> writes:

> I want to find if the particular group exist in my active directory

Search on the group's DN, specifying SCOPE_BASE as the search scope.  If
you get a result, then the group exists, otherwise it doesn't.

> also another function to find the user in a particular group

Do the same search as above, returning the "member" attribute.  Get
the search result and then inspect the list of returned members.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Mysterious Logging Handlers

2016-09-09 Thread John Gordon
In <247db0ab-efe7-484b-a418-dd219f68a...@googlegroups.com> Josh English 
<joshua.r.engl...@gmail.com> writes:

> When I run the scriptI get logging information from only xlreader, not
> from the main script:

> DEBUG:XLREADER:Creating Excel Reader

> This format isn't defined anywhere.

That is the default logging format; it's used when you haven't supplied any
format of your own.  The snippet of xlreader.py does not define any format,
so it seems like that's where it's coming from.

(This seems pretty straightforward; am I missing something?)

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: How to split value where is comma ?

2016-09-08 Thread John Gordon
In <mailman.39.1473302345.2411.python-l...@python.org> Joaquin Alzola 
<joaquin.alz...@lebara.com> writes:

> Use the split

> a.split(",")
> for x in a:
> print(x)

This won't work.  split() returns a list of split elements but the
original string remains unchanged.

You want something like this instead:

newlist = a.split(",")
for x in newlist:
print(x)

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: JSON result parsing

2016-07-29 Thread John Gordon
In <fd02ca3a-47af-4a0b-b309-56bc732ea...@googlegroups.com> TUA 
<kai.pet...@gmail.com> writes:

> I want to retrieve the value for a key 'ID' but only if I have a single 
> result and, obviously, if ID is present.

> How can I do this with pythonic elegance?

> Thanks for all suggestions!

if len(results) == 1 and 'ID' in results:
return results['ID']

else:
return 'something else'

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: what the heck this code is doing?

2016-07-01 Thread John Gordon
In <3bbddafc-dcd6-4d5c-84f4-94077b5bc...@googlegroups.com> Basant Dagar 
<dagar.basa...@gmail.com> writes:

> def lookup(d, keyval):
> found = False
> for child in d:
> if found : return child.text
> if child.tag == 'key' and child.text == keyval :
> found = True
> return None

> trackID = lookup(entry, 'Track ID')

> Below is the main part of input xml file data, it passes to lookup function:

> Track ID369

> what I don't get is. How in the world it returns value 369 for the variable 
> 'trackID'??

It loops through the child items in entry, looking for one with a
'key' value of 'Track ID'.  If it finds one, it sets found=True and
loops one more time, returning the text of the *next* child element.

It depends on the 'key' element being directly followed by the 'integer'
element within entry.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Break and Continue: While Loops

2016-06-23 Thread John Gordon
In <639b00e0-7b9d-4ed4-96ad-6afbcd536...@googlegroups.com> Elizabeth Weiss 
<cake...@gmail.com> writes:

> i=0
> while 1==1:
>print(i)
>i=i+1
>if i>=5:
>  print("Breaking")
>  break

> Why is Breaking going to be printed if i only goes up to 4?

Your code prints i and THEN adds one to it.

So i is 4, it gets printed, then 1 is added to it, so it becomes 5
and then the loop exits.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: while Loops

2016-06-22 Thread John Gordon
In <0cf9a94e-b84c-460d-b03d-edf6a941a...@googlegroups.com> Elizabeth Weiss 
<cake...@gmail.com> writes:

> Why is one of the results 5 since i=i+1? Should the maximum result
> be 4 since 4 +1=5? 

"while i<=5" means "while i is less than or equal to 5".  So the loop
will keep going at 5, and only stop when i is 6.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: how to for loop append a list [] when using parallel programming

2016-06-15 Thread John Gordon
In <fabcecae-04ae-433c-aad8-43993a21e...@googlegroups.com> meInvent bbird 
<jobmatt...@gmail.com> writes:

> how to for loop append a list [] when using parallel programming

items = []
for item in parallelized_object_factory():
items.append(item)

If you want a more specific answer, ask a more specific question.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: log file.

2016-06-14 Thread John Gordon
In <05d2df77-8cd0-467b-8ab3-54bf730d8...@googlegroups.com> 
owenpaul...@gmail.com writes:

> I have a programme to pump out water from a sump and would like to
> log to a readable file when the pump operates. what is the easiest
> way to acheive this with python 3.

Are you asking for help with logging, or communicating with the pump?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: how to solve memory

2016-06-10 Thread John Gordon
In <8a1c372e-bd6c-4923-8ae1-8f129ec74...@googlegroups.com> meInvent bbird 
<jobmatt...@gmail.com> writes:

> > I already responded to your earlier post about this program.  Did you
> > read it?

> sorry i missed your reply post, 
> i find post by me and search your name, no this name
> is your name changed in previous post?

My comment was that the recursive calls weren't indented in the
"if deep > 0" block, therefore DFS was being called infinitely with smaller
and smaller values of deep.  But it appears you have fixed that issue.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: how to solve memory

2016-06-10 Thread John Gordon
In <4f853aa2-cc00-480b-9fd7-79b05cbd4...@googlegroups.com> meInvent bbird 
<jobmatt...@gmail.com> writes:

> https://drive.google.com/file/d/0Bxs_ao6uuBDULVNsRjZSVjdPYlE/view?usp=sharing

I already responded to your earlier post about this program.  Did you
read it?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: why it is like stop running after a 3 seconds

2016-06-09 Thread John Gordon
In <35cd5920-1fbb-441f-9fc6-2f3f2e5f8...@googlegroups.com> Ho Yeung Lee 
<davidbenny2...@gmail.com> writes:

> i write a program, it is like forever loop
> but i only restrict it to run 2 level recursively, 

I don't think the restriction is working.  There is "if deep > 0:"
at the top of the function, but the recursive calls aren't inside that
if block.  DFS keeps calling itself with smaller and smaller values of
deep.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Unit test a class with xml elements

2016-05-24 Thread John Gordon
In <4c25c98f-9cf0-4a70-b33b-1d2c982de...@googlegroups.com> Palpandi 
<palpandi...@gmail.com> writes:

> Hi,

> How can I unit test a class which using xml elements?
> There is a posiibility of different combinations of xml.

> What is the better way to test this kind of class?
> XML binding is used here.

> Share if any examples available.

Create your own sample XML illustrating each desired combination.

Then write test cases for each.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: ZipImportError: can't find module

2016-05-24 Thread John Gordon
In <1e511b73-e984-459c-9311-77bcd...@googlegroups.com> loial 
<jldunn2...@gmail.com> writes:

> What has been working for years suddenly has an error :

> zipimport.ZipImportError: can't find module 'mymodule'

How is the shell script executed?  Is it run interactively, or from a cron
job?

Are the permissions on the zipfile correct, and all parent directories?

How, specifically, are you importing the module?  Are you doing something
like this:

zipfile = zipimport.zipimporter('file.zip')
zipfile.load_module('mymodule')

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Program prints questions for user input, but won't show the answer output

2016-05-18 Thread John Gordon
In <1cc14787-7061-45c9-a70e-1b16e3f5e...@googlegroups.com> Jake Kobs 
<kob...@gmail.com> writes:

> Here is the code:

> def getHigh(pints, highPints):
> highPints = pints[0]
> counter = 1
> while counter < 7:
> if (pints[counter] > highPints):
> highPints = pints[counter]
> counter = counter + 1
> return highPints

getHigh() goes into an infinite loop if pints[counter] is less than or
equal to highPints.


> def getLow(pints, lowPints):
> lowPints = pints[0]
> counter = 1
> while counter < 7:
> if (pints[counter] < lowPints):
> lowPints = pints[counter]
> counter = counter + 1
> return lowPints

And getLow() has a very similar problem.

I suspect you want to unindent the 'counter = counter + 1' statement
so that it is NOT inside the 'if' statement.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Python 3.5.1 Not Working

2016-05-13 Thread John Gordon
In <mailman.632.1463156502.32212.python-l...@python.org> Aidan Silcock 
<aidan_silc...@yahoo.co.uk> writes:

>   On Fri, 13 May, 2016 at 16:59, Aidan Silcock<aidan_silc...@yahoo.co.uk> 
> wrote:
> Hello I have tried to download python 3.5.1 today and it has downloaded
> but each time I try to open it it says I need to Modify, Repair or
> Uninstall the program.I have tried repairing it neumerous times and it
> will say it was successful but then when I go to open it again it comes
> up with the same message.Can you help?Aidan

Hi Aidan,

Are you using Windows XP?  Unfortunately, versions of Python above 3.4.3
do not support Windows XP.  You'll have to download version 3.4.3 if you
are using Windows XP.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Simplest way to locate a string in a column and get the value on the same row in another column

2016-04-28 Thread John Gordon
In <mailman.209.1461869020.32212.python-l...@python.org> David Shi 
<davidg...@yahoo.co.uk> writes:

> What is the simplest way to locate a string in a column and get the value
> on the same row in another column ?

You haven't given enough context for us to be able to answer.

Are you talking about a spreadsheet, a database table, an HTML table,
or something else?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Python path and append

2016-04-25 Thread John Gordon
In <27nshbp40p1llr231dqm31p754tvurk...@4ax.com> Seymore4Head 
<Seymore4Head@Hotmail.invalid> writes:

> On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head
> <Seymore4Head@Hotmail.invalid> wrote:

> I am going to forget using a directory path.
> I would like to take the file win.txt and append a space and the *
> symbol.

> f = open('win.txt', 'r+')
> for line in f:
> f.read(line)
> f.write(line+" *")

> This doesn't work.  Would someone fix it please?  It is for a task I
> am trying to accomplish just for a home task.

It's much easier to create a new file and then rename it afterwards,
instead of rewriting the original file.

import os

f_in = open('win.txt', 'r')
f_out = open('win_new.txt', 'w')

for line in f_in.read().splitlines():
f_out.write(line + " *\n")

f_in.close()
f_out.close()

os.rename('win.txt', 'win_old.txt')
os.rename('win_new.txt', 'win.txt')

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Pyscripter Issues

2016-03-31 Thread John Gordon
In <mailman.261.1459432779.28225.python-l...@python.org> Simon Martin 
<martinsr1...@gmail.com> writes:

> I have been having issues trying to run python 3.5.1 and pyscripter 2.6.
> Giving the error message that it cannot initialize python.

Which version of Python did you get: 32-bit or 64-bit?  I vaguely recall
that PyScripter won't work with the 64-bit version.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Not downloading

2016-03-23 Thread John Gordon
In <mailman.66.1458758388.2244.python-l...@python.org> louis anderson 
<louisanderson...@hotmail.com> writes:

> After a workshop in my school today regarding python i have downloaded
> it on my laptop

Since you were in fact able to download it, your message title of
"Not downloading" is somewhat misleading...

> however when i go to launch it it either tells me to modify python
> repair python or uninstall python. It will not let me go onto python
> at all.

What operating system do you have on your laptop, and what version of
Python are you trying to install?

Python 3.5 is known to have trouble installing on Windows XP.  If you
have Win XP, try using an older 3.4 version of Python.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: from a module return a class

2016-03-19 Thread John Gordon
In <56eaecc8$0$3658$426a7...@news.free.fr> Laurent Pointal 
<laurent.poin...@free.fr> writes:

> >> user_pword = promptUser_PWord()
> > 
> > Show us the complete definition of promptUser_PWord().

> AFAIU It looks to be the module…

If it were a module, it wouldn't be callable.  It has to be a function
or a class.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: from a module return a class

2016-03-19 Thread John Gordon
In <b4647f72-bf8a-4adb-ba1d-bd7d684ba...@googlegroups.com> kevind0...@gmail.com 
writes:

> ##  prompt the user for a User name a& pWord
> user_pword = promptUser_PWord()   

> I get the error 
>   File "H:\dev\eclipse\workspace\genXls\src\genXls\promptUser_PWord.py", line 
> 58
> return user_pword
> SyntaxError: 'return' outside function

Show us the complete definition of promptUser_PWord().

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: from a module return a class

2016-03-18 Thread John Gordon
In <cc439011-f9b3-4837-ba3b-6703f99ae...@googlegroups.com> kevind0...@gmail.com 
writes:

> As requested , full code for promptUser_PWord



So promptUser_PWord is a module?  Well, I'm confused.  You gave us this
bit of code:

user_pword = promptUser_PWord()   

But that can't work if promptUser_PWord is a module; modules aren't
callable.  promptUser_PWord() has to be a function or a class.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: from a module return a class

2016-03-18 Thread John Gordon
In <mailman.332.1458315013.12893.python-l...@python.org> Wolfgang Maier 
<wolfgang.ma...@biologie.uni-freiburg.de> writes:

> > So promptUser_PWord is a module?  Well, I'm confused.  You gave us this
> > bit of code:
> >
> >  user_pword = promptUser_PWord()
> >
> > But that can't work if promptUser_PWord is a module; modules aren't
> > callable.  promptUser_PWord() has to be a function or a class.
> >

> Yes, but I guess the OP's program will run into the SyntaxError when 
> trying to import the module, i.e., before it ever encounters the 
> TypeError: 'module' object is not callable.

Good point; I hadn't thought of that.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: password and username code

2016-03-06 Thread John Gordon
In <1ed89545-f102-4538-bfe2-9d0e3dac8...@googlegroups.com> 
=?UTF-8?B?w5ZtZXIgc2FyxLE=?= <sari.omer.1...@gmail.com> writes:

> l want program if username is not registered, register first,
> then store it, and l want program ask for some specific characters,
> like 1,2,3../,%. 

What is your process for finding out if a name is registered?  There
are lots of possible ways to do it.  Do you have one in mind?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: list reversal error

2016-03-03 Thread John Gordon
In <8b3d06eb-0027-4396-bdf8-fee0cc9ff...@googlegroups.com> vlyamt...@gmail.com 
writes:

> i have list of strings "data" and i am trying to build reverse list data1
> data1 = []
> for i in range(len(data)):
>j = len(data) - i
>data1.append(data[j])

> but i have the following error:
> data1.append(data[j])
> IndexError: list index out of range
>  
> am i doing it wrong?
> Thanks

Python lists are zero-indexed, meaning a list of five items will have
indexes 0 to 4.

The first time through your loop, i is 0, so

j = len(data) - i 

evaluates to

j = len(data)

which would yield 5 for a five-element list, but the last actual element
is in data[4].

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Continuing indentation

2016-03-03 Thread John Gordon
In <871t7sbkex@elektro.pacujo.net> Marko Rauhamaa <ma...@pacujo.net> writes:

> Ethan Furman <et...@stoneleaf.us>:

> > No, it isn't.  Using '\' for line continuation is strongly discouraged.

> Why would you discourage valid syntax?

Some things that are permissible may not be desirable.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: importing: what does "from" do?

2016-01-21 Thread John Gordon
In <n7qpel$a3j$1...@dont-email.me> "Charles T. Smith" 
<cts.private.ya...@gmail.com> writes:

>   from utilities import hexdump

> ImportError: cannot import name hexdump

The most likely explanation here is that the 'utilities' module simply
does not contain something named 'hexdump'.

Have you inspected the 'utilities' module?  Does it, in fact, contain
something named 'hexdump'?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: importing: what does "from" do?

2016-01-21 Thread John Gordon
In <n7qu0c$a3j$3...@dont-email.me> "Charles T. Smith" 
<cts.private.ya...@gmail.com> writes:

> > The most likely explanation here is that the 'utilities' module simply
> > does not contain something named 'hexdump'.
> > 
> > Have you inspected the 'utilities' module?  Does it, in fact, contain
> > something named 'hexdump'?

> Yes

In that case, the problem is most likely a circular import issue, as you
mentioned.  The only way to fix it is to reorganize your modules.

How did this error come up?  Did the code work previously?  If so, what
changed?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: importing: what does "from" do?

2016-01-21 Thread John Gordon
In <n7qugv$a3j$4...@dont-email.me> "Charles T. Smith" 
<cts.private.ya...@gmail.com> writes:

> > How did this error come up?  Did the code work previously?  If so, what
> > changed?

> The developers of this legacy code had this as well as other functions
> duplicated throughout the system, in order to avoid confronting these
> issues.

Yes, but did the code work previously?  If so, what changed?

> I'm trying to untangle the mess - without rewriting thousands of lines
> of application code.

At worst you'd have to move some things into a new module, and change the
statements that import those things.  You shouldn't have to rewrite any of
the actual code.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Question about a class member

2016-01-07 Thread John Gordon
In <a199a9b7-784e-4e12-8030-4e3fffd63...@googlegroups.com> Robert 
<rxjw...@gmail.com> writes:

> I am using a download package. When I read its code, see below please, I 
> don't know what 'sample' is:

> --
> model = hmm.GaussianHMM(n_components=4, covariance_type="full")

> model.startprob_ = startprob
> model.transmat_ = transmat
> model.means_ = means
> model.covars_ = covars

> # Generate samples
> X, Z = model.sample(50)
> -

sample() is a method in the GaussianHMM class.  (In this case, it's
a method in the _BaseHMM class, from which GaussianHMM inherits.)

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: imshow keeps crashhing

2016-01-06 Thread John Gordon
In <a23096d2-7144-4736-9546-8cd863c26...@googlegroups.com> 
darren.mcaf...@gmail.com writes:

> So scipy is making temporary files in
> /private/vars/folders/w4//

Are there any unusual characters in ?  That's usually more
of a Windows issue, but I'm grasping at straws here :-)

> 1. When in the correct folder within Terminal, on the command line I can do: 
> open  
> And it will open it in Preivew.

So the actual command name for running Preview is "open"?  Have you tried
setting the SCIPY_PIL_IMAGE_VIEWER variable to that name?

> 2. However, when opening Preview first, it is impossible (for me) to navigate 
> to the /private directory to open the file that way, even with: 
> defaults write com.apple.Finder AppleShowAllFiles YES
> turned on.

You mean you can't use Preview's file-selection interface to select the
desired file?  The /private directory is not navigable?  Does it even
show up as a choice?

Is there something special about the /private directory?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: imshow keeps crashhing

2016-01-06 Thread John Gordon
In <eefe98a3-9e49-468f-b57f-cf4ad6bb9...@googlegroups.com> 
darren.mcaf...@gmail.com writes:

> Hi John,

> I am on a mac and have set the following:

> SCIPY_PIL_IMAGE_VIEWER=/Applications/Preview.app/Contents/MacOS/Preview

> And when using imshow(), sure enough Preview attempts to open the fie,
> but it throws the following error: The file "tmp1zuvo7wn.png" couldn't be
> opened because you don't have permission to view it.

> I can open the temporary file manually no problem. And I have played
> around with chmod 0644 , but nothing seems to work.

> I have a feeling this is El Capitan specific. Do you have any
> suggestions?

I don't really know much about Macs...

Can you run Preview and open the temporary file successfully?

When launched from scipy, Does Preview run as a user other than yourself?

What are the permissions on the temporary file when it's originally
created?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Why is there difference between cmd line and .py file?

2016-01-05 Thread John Gordon
In <e9f1d94f-4dd6-49b5-bf5c-bbcdc8d30...@googlegroups.com> Robert 
<rxjw...@gmail.com> writes:

> 
> # represent the experiments
> head_counts = np.array([5,9,8,4,7])

The code doesn't define 'np', so this line should produce an error.

The code you linked contains this import:

import numpy as np

However you didn't show it here, so I wonder if you posted the real code.

> sum(expectation_A)[0]
> ---
> IndexErrorTraceback (most recent call last)
>  in ()
> > 1 sum(expectation_A)[0]

> IndexError: invalid index to scalar variable. 
> //

The built-in function sum() returns a single value, not a list, so this
is a reasonable error.

I suspect the code actually intended to call numpy.sum(), which does
return a list (or something like a list).

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: imshow keeps crashhing

2015-12-22 Thread John Gordon
In <a7993a64-837e-4062-a856-d40acc35f...@googlegroups.com> norou...@gmail.com 
writes:

> Can anyone please help me with "imshow"? I have tried "imshow" on different 
> computers and different Python consoles but it does not work. Here are the 
> code and the error message:

> import scipy.misc as mi
> img = mi.imread('C:\images\circles.png')
> mi.imshow(img)

> 'see' is not recognized as an internal or external command,
> operable program or batch file.

scipy calls an external image viewer program to display the image.

The name of this program is stored in the environment variable
SCIPY_PIL_IMAGE_VIEWER.  If that variable is not present, it uses
'see' by default.

Do you have a suitable image viewing program installed on your computer?
If so, try setting the SCIPY_PIL_IMAGE_VIEWER environment variable to the
name of that program.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: error reading api with urllib

2015-12-16 Thread John Gordon
In <9aa21642-765b-4666-8c66-a6dab9928...@googlegroups.com> simian...@gmail.com 
writes:

> Bad Request
> b''


That probably means you aren't using one of the recognized methods
(i.e. GET, POST, etc.)

It doesn't look like you are specifying one of these methods on your
Request object.  Try doing that.

(It works in your browser because it defaults to GET automatically.)

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Is vars() the most useless Python built-in ever?

2015-12-01 Thread John Gordon
In <4f0f7fc5-c93a-4223-9c05-e192a8faf...@googlegroups.com> Rick Johnson 
<rantingrickjohn...@gmail.com> writes:

> Your lament does remind me of a pet peeve i have concerning Python, and
> that is, the lie about: "THERE SHOULD BE ONE (AND PREFERABLY ONLY ONE)
> WAY TO DO IT!". In fact, in python there is almost always *MANY* ways to
> achieve the same output.=20

The koan reads:

There should be one-- and preferably only one --obvious way to do it.

You left out the rather important word "obvious".

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: if else python

2015-11-26 Thread John Gordon
In <mailman.51.1448431821.20593.python-l...@python.org> Scott Montreuil 
<sc...@zml.ca> writes:

> I have an if statement which seems to run both commands and I cannot
> figure out why.

I'm not sure what you mean by "both commands".  Do you mean that the
'if' and 'else' branches both execute?

Your if/else branches are in a loop, so perhaps you're seeing the 'if'
branch on one loop iteration, anf the 'else' branch on the next iteration?

I see that your if and else branches both contain a screen.addstr()
call.  Are you seeing both of these outputs?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Finding scores from a list

2015-11-24 Thread John Gordon
In <277843f7-c898-4378-85ea-841b09a28...@googlegroups.com> Cai Gengyang 
<gengyang...@gmail.com> writes:


> results = [
> {"id": 1, "name": "ensheng", "score": 10},
> {"id": 2, "name": "gengyang", "score": 12},
> {"id": 3, "name": "jordan", "score": 5},
> ]

Okay, this is a list.

> I want to find gengyang's score. This is what I tried :

> >>> print((results["gengyang"])["score"])

> but I got an error message instead :

> Traceback (most recent call last):
>   File "<pyshell#62>", line 1, in 
> print((results["gengyang"])["score"])
> TypeError: list indices must be integers, not str

Lists are indexed by number, not by name.

You want something like this:

for result in results:
if result["name"] == "gengyang":
print result["score"]
break

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: anyone tell me why my program will not run?

2015-11-22 Thread John Gordon
In <1737402a-2f4d-440a-abd7-6cc500f67...@googlegroups.com> Dylan Riley 
<dylan.ri...@hotmail.com> writes:

> heads = int("1")

Why are you taking the int value of a string constant?  If you know you
want the value 1, why not just use it directly?

> flips = 100
> headscount = 0
> tailscount = 0

> while flips != 0:
> flips -= 1

This loop has no other effect than to set flips to zero, so why not just
set flips to zero in the first place?

> result = random.randint(heads, tails)
> if result = heads:
> headscount += 1
> else:
> tailscount += 1

Perhaps you meant to have this piece of code indented under the while
loop above?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: What is a function parameter =[] for?

2015-11-18 Thread John Gordon
In <d9045bdd-a5d4-4c5c-9fd3-3d54f6b50...@googlegroups.com> fl 
<rxjw...@gmail.com> writes:

> Hi,

> I have tried the below function and find that it can remember the previous
> setting value to 'val'. I think the second parameter has something on this 
> effect, but I don't know the name and function of '=[]' in this application.

> Could you explain a little to me?
> Thanks,

> def eList(val, list0=[]):
> list0.append(val)
> return list0
> list1 = eList(12)
> list1 = eList('a')

That is a default parameter.  If eList() is called without an argument for
list0, it will use [] as the default value.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Is there any reason to introduce this intermediate variable (sz)?

2015-11-17 Thread John Gordon
In <bad9ac66-38aa-4445-a486-6df0e9c77...@googlegroups.com> fl 
<rxjw...@gmail.com> writes:

> correctly. Could you see something useful with variable 'sz'?

'sz' is fewer characters than '(n_iter,)', which may make your code easier
to read.

The np.zeros() function explicitly accepts an 'int or sequence of ints',
so you don't specifically need a sequence.  Is the same true for the
'size' keyword argument of np.random.normal()?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Is there any reason to introduce this intermediate variable (sz)?

2015-11-17 Thread John Gordon
In <c9b5f60f-b1ec-4857-bb02-2748a28b5...@googlegroups.com> fl 
<rxjw...@gmail.com> writes:

> I still don't see the necessity of 'sz'. Thanks,

sz isn't required.  You can use (n_iter,) in place of sz.

However, as I posted earlier, sz is shorter so it might make your code
easier to read.

Using sz can also lead to easier code maintenance.  If the contents of
the tuple were ever to change, it would be much easier to simply change
it in once place (the definition of sz), rather than having to edit
several different occurrences of (n_iter,) in your code.


-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Is it useful for re.M in this example?

2015-11-12 Thread John Gordon
In <fc8a4061-5156-41c8-bfd7-d9a8da462...@googlegroups.com> fl 
<rxjw...@gmail.com> writes:

> re.M  Makes $ match the end of a line (not just the end of the string) and
>  makes ^ match the start of any line (not just the start of the string).

> But I don't see the reason to put re.M in the example project:

That's because your sample string does not contain newline characters.
If it did, you would see the effect of re.M.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Why does 'as' not recognized?

2015-11-12 Thread John Gordon
In <8ddbc8fd-ebdb-4cd2-8e3b-b0e1f5142...@googlegroups.com> fl 
<rxjw...@gmail.com> writes:

> >>> cats = ['Tom', 'Snappy', 'Kitty', 'Jessie', 'Chester']
> >>> 
> >>> type(cats)
> 
> >>> cats[2]
> 'Kitty'
> >>> as=cats[2]
> SyntaxError: invalid syntax
> >>> as=cats
> SyntaxError: invalid syntax
> >>> as
> SyntaxError: invalid syntax

'as' is a python language keyword, and cannot be used for variable names.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: new to python, help please !!

2015-11-11 Thread John Gordon
In <93aef8e5-3d6f-41f4-a625-cd3c20076...@googlegroups.com> Anas Belemlih 
<anas.belem...@gmail.com> writes:

> i=0
> s1=line1[i]
> s2=line2[i]
> count = 0

> if number1 != number2:
>   print " hash table not the same size"
> else:
> while count < number1:
>   if s1 == s2:
>   print " character", line1[i]," matchs"
>   i=i+1
>   count=count+1
>   else
>   print "Hash values corrupt"

It looks like you're expecting s1 and s2 to automatically update their
values when i gets incremented, but it doesn't work like that.  When you
increment i, you also have to reassign s1 and s2.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: How to handle exceptions properly in a pythonic way?

2015-11-02 Thread John Gordon
In <4b303213-62e2-42d4-b2f6-4fc1f6025...@googlegroups.com> zljubi...@gmail.com 
writes:

> Let's say that I have the following simple function:

> def get_html(url):

> wpage = requests.get(url)
> 
> return wpage.text

> How to handle exceptions properly that can arise during execution of the
> requests.get(url)?

The best way is probably to do nothing at all, and let the caller handle
any exceptions.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: If one IF is satisfied, skip the rest in the nest...

2015-10-21 Thread John Gordon
In <50a6789a-3965-430b-9a91-b08adcedf...@googlegroups.com> 
bigred04...@gmail.com writes:

> So here what I have, I have a 3 IF's within the same level.  If one IF is s=
> atisfied, I would like to "skip" the other IFs and continue with my code.

> # 4 second open
> if wb1_sheet1.cell(row=cell + 1, column=2).value == 0 and 
> wb1_sheet1.cell(row=cell + 1, column=3).value == 0 and 
> wb1_sheet1.cell(row=cell + 2, column=2).value == 0 and 
> wb1_sheet1.cell(row=cell + 2, column=3).value == 0 and 
> wb1_sheet1.cell(row=cell + 3, column=2).value == 0 and 
> wb1_sheet1.cell(row=cell + 3, column=3).value == 0:
> open += 3
> open_seconds += 4
> start = wb1_sheet1.cell(row=cell + 4, column=2).coord=
> inate
> break
> # 3 second open
> if wb1_sheet1.cell(row=cell + 1, column=2).value == 0 a=
> nd wb1_sheet1.cell(row=cell + 1, column=3).value == 0 and wb1_sheet=
> 1.cell(row=cell + 2, column=2).value == 0 and wb1_sheet1.cell(row=
> =cell + 2, column=3).value == 0:
> open += 3
> start = wb1_sheet1.cell(row=cell + 3, column=2).coord=
> inate
> open_seconds += 3
> continue
> # 2 second open
> if wb1_sheet1.cell(row=cell + 1, column=2).value == 0 a=
> nd wb1_sheet1   .cell(row=cell + 1, column=3).value == =
> 0:
> open += 3
> start = wb1_sheet1.cell(row=cell + 2, column=2).coord=
> inate
> open_seconds += 2


> if any but the last IF is true, then all IFs will be true...that's my probl=
> em.

It looks like all three of your if statements start out with this condition:

if wb1_sheet1.cell(row=cell + 1, column=2).value == 0 and 
wb1_sheet1.cell(row=cell + 1, column=3).value == 0

So you could reorganize your code by putting an if statement at the top
that only checks this condition.  Then, indented underneath, you can
check for the other conditions.

And be sure to use "else" and "elif" when they are appropriate.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Trouble running

2015-10-06 Thread John Gordon
In <mailman.409.1444115369.28679.python-l...@python.org> 
=?utf-8?Q?Cameroni123_=E2=84=A2?= <cameronbel...@gmail.com> writes:

> Hi I have recently installed python on windows 10 and I'm trying to
> save in order to run the module and I cant I don't know why, could
> you please help?
> Cameron

We need more details to help you.

What program are you using to try to save?  Is it a text editor?

What happens when you try to save?  How do you know it didn't work?
Do you get an error message?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Check if a given value is out of certain range

2015-10-01 Thread John Gordon
In <560d78e2$0$1618$c3e8da3$54964...@news.astraweb.com> Steven D'Aprano 
<st...@pearwood.info> writes:

> > I have to parse those damn brackets and then figure out the inverted
> > logic. Give me x < 0 or x > 10 any day of the week.  When you're an old,
> > senile git like me, readability counts :-)

> With the greatest of respect Mark, I don't believe that for a second. Your
> sig line, which you have used without fail for more years than I can
> remember includes the phrase "ask not what our language can do for you". If
> you can understand that, I don't believe that you cannot figure out how to

Certainly we can understand it.  But it takes ever-so-slightly more effort
to do so.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Check if a given value is out of certain range

2015-10-01 Thread John Gordon
In <560d8726$0$1602$c3e8da3$54964...@news.astraweb.com> Steven D'Aprano 
<st...@pearwood.info> writes:

> > But it takes ever-so-slightly more effort to do so.

> Slightly more effort than what alternative? How would you communicate the
> idea of *not* asking for X without using the concept of "not"?

I wasn't commenting directly to the "ask not..." quote; I was referring
upthread to the choice between

not 0 <= x <= 10

and

x < 0 or x > 10

Both are of course understandable, but in my opinion, the latter one takes
slightly less effort to grok.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Check if a given value is out of certain range

2015-10-01 Thread John Gordon
In <87r3le1ht3@elektro.pacujo.net> Marko Rauhamaa <ma...@pacujo.net> writes:

> > I wasn't commenting directly to the "ask not..." quote; I was
> > referring upthread to the choice between
> >
> > not 0 <= x <= 10
> >
> > and
> >
> > x < 0 or x > 10
> >
> > Both are of course understandable, but in my opinion, the latter one
> > takes slightly less effort to grok.

> Wouldn't

>x < 0 or 10 < x

> be even more visual?

I don't know what you mean by "more visual".

In my opinion, when comparing a variable to a constant, it's more natural
to have the variable on the left and the constant on the right, so that's
one strike against this code.

Another strike is that the code isn't consistent with itself; it puts the
variable on the left in the first comparison, then swaps to the right for
the second comparison.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Check if a given value is out of certain range

2015-09-30 Thread John Gordon
In <mugaov$79k$1...@speranza.aioe.org> alister 
<alister.nospam.w...@ntlworld.com> writes:

> I would stick with the OP's current solution

> Readability Counts!

I agree.  'if x < 0 or x > 10' is perfectly fine.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Question re class variable

2015-09-29 Thread John Gordon
In <mudnfg$cqo$1...@speranza.aioe.org> alister 
<alister.nospam.w...@ntlworld.com> writes:

> why not simply use pythons builtin id function?
> each new instance of an object is automatically assigned a unique ID

It's only guaranteed to be unique for objects that exist at the same time.

If an object is created and destroyed and then another new object is
created, the ID of those two objects can be the same.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Django (Python Web Framework) Tutorial

2015-09-26 Thread John Gordon
In <1421a34f-d8cc-4367-adab-2c2b46504...@googlegroups.com> Cai Gengyang 
<gengyang...@gmail.com> writes:

> Question : I am a little confused about the last paragraph : What exactly
> is a "directory outside of the document root, such as /home/mycode." and
> how do you "Put your code in this directory" ?

Django is a web application framework.  So, you have to use it together with
a web server.  The "document root" is the directory where the web server
expects to find files to be served as web pages.

You said you put the Django project code in a subdirectory of your home
directory.  That should be fine.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Learning Modules, Arguments, Parameters (imma noob)

2015-09-24 Thread John Gordon
In <7ad8941d-04aa-42c5-82e9-10cdf02ab...@googlegroups.com> codyw...@gmail.com 
writes:

> I seem to be having a problem understanding how arguments and parameters
> work, Most likely why my code will not run. Can anyone elaborate on what
> I am doing wrong?

>  def get_input(kilo):
>kilo = float(input('Enter Kilometers: '))
>return kilo

get_input() gets all its input from the keyboard.  It doesn't need any
arguments.

>  def convert_kilo(kilo,miles):
>  miles = float(kilo * 0.6214)
>  print( kilo,' kilometers converts to ',miles,' miles')

convert_kilo() calculates miles on its own, so you don't need to pass it
as an argument.

> def main():
>get_input()
>convert_kilo()
>
>  main()

When calling get_input, you need to save the return value in a variable,
and then pass that variable as an argument to convert_kilo.

The updated code would look like this:

def main():
kilo = get_input()
convert_kilo(kilo)

def get_input():
kilo = float(input('Enter Kilometers: '))
return kilo

def convert_kilo(kilo):
miles = float(kilo * 0.6214)
print( kilo,' kilometers converts to ',miles,' miles')

main()

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Problem configuring apache to run python cgi on Ubuntu 14.04

2015-09-21 Thread John Gordon
In <44e870a7-9567-40ba-8a65-d6b52a8c5...@googlegroups.com> 
tropical.dude@gmail.com writes:

> print("Content-Type: text/html;charset=utf-8")
> print("Hello World!")

As I recall, you must have a blank line between the headers and the
content.

But that may or may not be your problem, as you haven't told us exactly
what is going wrong.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


  1   2   3   4   5   >