Re: [Tutor] Finding unique strings.

2019-05-03 Thread Roger B. Atkins
It would probably make things easier if you specified your operating
system, Python version, data file type and location.

Typically, the bank info would be downloadable as a CSV (comma
separated value) file. Assuming that to be the case, and assuming you
are using Windows, and assuming Python 3, and assuming you are downing
loading your data to a file stored on your computer and running your
reader program on the data file, you might start with something like:

#! python 3

import csv

deposits, atm, temp = [], [], []   # initializes column headings to empty lists.

filename = input('Enter file name: ')

with open("C:\\PyScripts\\" + filename, 'r') as f:
contents = csv.reader(f)
for row in contents:
 ...

You would substitute your own column names in place of 'deposits, atm'
and substitute your file path information in place of
"C:\\PyScripts\\".  The first row of the csv file will contain your
column headers. Therefore, as you read through the first row in the
file, row[0] would be the first header, row[1] would be the second
header and so forth.  As you read the second row, row[0] would be the
first value (data element) under the first column header, row[1] would
be the first value under the second column header and so forth.  For
example, if you were searching for deposits, assuming 'Deposits' is
the 3rd column header, you could use code such as deposits += row[2]
to add deposit values to your list of deposits. Such code would be
indented under 'for row in contents' to make it part of the 'for'
loop.

Hopefully this will give you some ideas to get you started.



to


On Fri, May 3, 2019 at 5:40 AM  wrote:
>
> All,
>
>
>
> I have a list of strings which has been downloaded from my bank. I am trying
> to build a program to find the unique string patterns which I want to use
> with a dictionary. So I can group the different transactions together. Below
> are example unique strings which I have manually extracted from the data.
> Everything after the example text is different. I cannot show the full data
> due to privacy.
>
>
>
> WITHDRAWAL AT HANDYBANK
>
> PAYMENT BY AUTHORITY
>
> WITHDRAWAL BY EFTPOS
>
> WITHDRAWAL MOBILE
>
> DEPOSIT  ACCESSPAY
>
>
>
> Note: Some of the entries, have an store name contained in the string
> towards the end. For example:
>
>
>
> WITHDRAWAL BY EFTPOS 0304479 KMART 1075   CASTLE HILL 24/09
>
>
>
> Thus I want to extract the KMART as part of the unique key. As the shown
> example transaction always has a number. I was going to use a test condition
> for the above to test for the number. Then the next word would be added to
> the string for the key.
>
>
>
> I tried to use dictionaries and managed to get unique first words. But got
> stuck at this point and could not work out how to build a unique keyword
> with multiple words. I hope someone can help.
>
>
>
>
>
> Sean
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] str.replace error

2019-04-25 Thread Roger Lea Scherer
I'm working wtih python 3.7 on Windows 10.
I'm trying to write some code in order to clean up the data in the csv file.
Using spreadsheet language, I want to replace part of a cell ("Basic P1")
with an empty string and write it in the comments cell.
I thought assigning a variable and replacing the string would be a good
idea.

Here is my code:

import csv

with open('somefile') as csvDataFile:
csvReader = csv.reader(csvDataFile)
for row in range(100):
a = "Basic P1"
str.replace(a, "")
print(next(csvReader))

I get an error:

Traceback (most recent call last):
  File "somefile", line 7, in 
str.replace(a, "")
TypeError: replace() takes at least 2 arguments (1 given)

But I think I have 2 arguments: a being the "old" argument as per the
documentation, "" being the "new" argument as per the documentation.

What am I missing?

-- 
Roger Lea Scherer
623.255.7719

  *Strengths:*
   Input, Strategic,
Responsibility,

Learner, Ideation
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: A bit of humor related to my sporadic quest to learn Python

2019-01-13 Thread Roger B. Atkins
Ditto, but the angle is steeper, I've lost my climbing equipment, and the
volcano is erupting.

On Sun, Jan 13, 2019 at 5:44 PM boB Stepp  wrote:

> My son sent me this link, which I think captures my situation with
> Python quite nicely:
>
> https://cdn-images-1.medium.com/max/720/1*7RZKI-g4K_syDf6XQEGWKw.jpeg
>
> --
> boB
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I think I've broken my Python

2018-11-12 Thread Roger B. Atkins
What about installing or reinstalling Django using the python version
that produced the error message?
On Mon, Nov 12, 2018 at 10:10 AM Matthew Ngaha  wrote:
>
> On Mon, Nov 12, 2018 at 3:31 PM Mats Wichmann  wrote:
> >
> > Reconstruct the virtualenv you want maybe? Their whole concept is that
> > they're cheap and easy and can just be thrown away.  Of course, you then
> > have to remember what you did to create it in order to make a new one...
>
> It's been 3 years, I'm clueless as to how I created it. Also I'm a
> noob when it comes to Linux which makes this even more confusing for
> me. The 3 years I've been absent from Programming I went back to
> Windows.
>
> > Since you're on a Linux platform, use "which" to see how the names you
> > are typing are resolving
> >
> > which python
> > which python3
>
> The "command" gives this output:
>
> (website) matthew@linux-oq68:~/Documents/mywork/web/website/blogsite>
> which python
> /usr/bin/python
> (website) matthew@linux-oq68:~/Documents/mywork/web/website/blogsite>
> which python3
> /usr/bin/python3
>
> > Usually if the virtualenv has been broken by external factors, it won't
> > even activate. Are you sure you remembered to try to activate it?
> >
> Yep, I double checked to make sure I remembered to try to activate it.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Request for help with code

2018-11-07 Thread Roger B. Atkins
Gmail: Click Compose (Upper Left corner)
Window opens. In lower right corner within the compose window, click
on the 3 stacked dots.
Select text only.
On Wed, Nov 7, 2018 at 1:39 AM Adam Eyring  wrote:
>
> When I post code with questions, I just copy and paste from Python IDLE
> 3.6. Colors are removed, but indentation is preserved.
>
> On Tue, Nov 6, 2018 at 6:59 PM Mats Wichmann  wrote:
>
> > On 11/6/18 4:36 PM, Joseph Gulizia wrote:
> > > Funny using a text editorand showed indented in my browser.
> >  Won't
> > > bother the list again.
> >
> > We don't want you to "not bother" us, just hoping to get things in a
> > state where we can actually help...
> >
> > here's what we end up seeing:
> >
> > https://www.mail-archive.com/tutor@python.org/msg79222.html
> > https://www.mail-archive.com/tutor@python.org/msg79225.html
> >
> > since unlike most other languages, indentation is a crucial part of the
> > syntax, we tend to grumble.
> >
> > there must be some solution... guys, do you know of any alternate way to
> > send a message to the list if a mail client isn't cooperating? or do we
> > have instructions for beating gmail into submission?  Obviously gmail is
> > a key part of the modern infrastructure despite its (ahem) misfeatures.
> >
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
> >
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Installing python

2018-11-04 Thread Roger B. Atkins
Thanks. That confirms some of my surmises. I may still have the
Anaconda version on one of my notebook computers. I may use that to
write and debug source code, since I like the Spyder IDE, and then
copy working programs to my main desktop computer to run them in
Windows with no virtual environment.
On Sat, Nov 3, 2018 at 7:39 AM Mats Wichmann  wrote:
>
> On 11/2/18 10:01 PM, Roger B. Atkins wrote:
> > Okay, but what about the virtual environments? Once the Windows 10
> > path environment variable has a version of Python added to it, Windows
> > will find it (I am using Win 10), but will it be found from within any
> > given virtual environment (venv), regardless of which version created
> > the environment? And if 3rd party packages have been installed within
> > a venv, will they be found a) by Windows, and b) by the Python version
> > within the venv, even if it was not used to install the packages?
>
> (a) when you activate a virtualenv, it will always find that python (the
> one the env was created from), that's what the activation does - fiddle
> paths so you see that envirnoment and not any other that may be sitting
> around.
>
> (b) when you pip install with a virtualenv active the installation will
> be private to that virtualenv.
>
> which leads to... Anaconda uses virtualenvs (afiak, _always_, rather
> than "when you ask for one" like many IDEs do), so, packages installed
> though Anaconda are in that sense "private".  They're not secret - you
> can see them all in the physical location where the virtualenv is set
> up, if you figure out where that is.
>
> > These questions confounded me until I finally deleted Anaconda, and
> > Python with it, because when running programs in Windows vice the
> > Spyder IDE, Windows could find Python, but not the 3rd party packages
> > such as pyperclip, bs4, and requests. I suspect it had something to do
> > with the Anaconda installation process establishing a venv, and the
> > package locations not existing (or not being visible) in Windows.
> I don't think developers of projects like Anaconda expect that their
> target users will try to run Python lots of different ways, so getting
> things all under their control is helpful and presents a consistent
> front, which is really the value the project brings - you want to do
> some (for example) scientific work in Python, and some notes tell you
> you need to install these 17 packages, and if you're on Windows, a
> couple of them maybe don't work because you don't have a C compiler
> installed - Anaconda puts that all in once place and makes it easier.
> Doesn't mean it isn't still occasionally confusing. If you need to run
> more versions, you can always install pkgs a second time, "outside" the
> Anaconda world. It should even be quick to do, pip caches packages it
> has downloaded so it probably won't even need to re-download.
>
>
> p.s. Python can tell you which Python it is running:
>
>   $ python
>   Python 2.7.15 (default, Oct 15 2018, 15:24:06)
>   [GCC 8.1.1 20180712 (Red Hat 8.1.1-5)] on linux2
>   Type "help", "copyright", "credits" or "license" for more information.
>   >>> import sys
>   >>> sys.executable
>   '/usr/bin/python'
>   >>>
>   $ source ~/virtualenv/py2/bin/activate
>   $ python
>   Python 2.7.15 (default, Oct 15 2018, 15:24:06)
>   [GCC 8.1.1 20180712 (Red Hat 8.1.1-5)] on linux2
>   Type "help", "copyright", "credits" or "license" for more information.
>   >>> import sys
>   >>> sys.executable
>   '/home/mats/virtualenv/py2/bin/python'
>   >>>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Installing python

2018-11-03 Thread Roger B. Atkins
Okay, but what about the virtual environments? Once the Windows 10
path environment variable has a version of Python added to it, Windows
will find it (I am using Win 10), but will it be found from within any
given virtual environment (venv), regardless of which version created
the environment? And if 3rd party packages have been installed within
a venv, will they be found a) by Windows, and b) by the Python version
within the venv, even if it was not used to install the packages?

These questions confounded me until I finally deleted Anaconda, and
Python with it, because when running programs in Windows vice the
Spyder IDE, Windows could find Python, but not the 3rd party packages
such as pyperclip, bs4, and requests. I suspect it had something to do
with the Anaconda installation process establishing a venv, and the
package locations not existing (or not being visible) in Windows.
That's just a WAG based on not being able to find the specified
directories in Windows Explorer. So, I'm just wondering if my quagmire
was part of or related to Mr. Scherer's, and whether he might have
similar problems if he goes back and forth between different virtual
environments.
On Fri, Nov 2, 2018 at 6:18 PM Alan Gauld via Tutor  wrote:
>
> On 02/11/2018 23:44, Mats Wichmann wrote:
>
> > that's actually exactly the right path for a Python 3.5+ if you chose a
> >  "user install", which you usually should.
>
> Ah, I always install for all users. That's why I've not
> seen that path presumably?
>
> But why *should* you install for a single user? I only
> ever do that for programs that I'm still writing and
> don't want other users to accidentally start. But I
> want everyone to be able to run my Python programs
> so I always install for everyone.
>
> > the "modern" answer for Windows is supposed to be the Python Launcher,
>
> I keep forgetting that thing exists. I really must spend
> some time getting to grips with it...
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Installing python

2018-11-02 Thread Roger Lea Scherer
Hey,

I have installed python 3.7 on my computer Windows10
(C:\Users\Roger\AppData\Local\Programs\Python\Python37), but when I go to
the git repository that holds all my projects and type "python --version"
in WindowsPowershell, I get Python 3.6.5.

So I guess my question is am I supposed to install python 3.7 in the git
repository? and a related question I think, am I supposed to install python
3.7 in every virtual environment I create, or is there a way to link python
to each virtual environment or each repo or each project?

I guess I'm so used to installing programs in Windows or Mac and having
them accessible globally (I guess is the word) that I expected python 3.7
to do the same thing, although I understand about programs written earlier
crashing because of upgrades, like from 2.7 to 3.4 for instance. I'm so
confused I'm not sure I even know what questions to ask, but the above
questions seem to be a missing link in my knowledge at this point.

Thank you as always.

-- 
Roger Lea Scherer
623.255.7719

  *Strengths:*
   Input, Strategic,
Responsibility,

Learner, Ideation


<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] pip install

2018-10-16 Thread Roger Lea Scherer
Hey all,

I'm trying to set up a virtual environment. I've used Windows Powershell on
my desktop with Windows 10. I was able only to get to 2.5 minutes of a 9.75
minute video before getting frozen, not just stuck. I was unable to
activate the batch file even though everything appeared to be where it
should be. I then found out about Linux Bash Shell for Windows and used
that, I next successfully installed virtualenv, but when I went to run it
it said command virtualenv not found but can be installed with sudo apt
install virtualenv, which I did, then tried to run 'virtualenv pdxCrime'
(without the apostrophes) and it errors out with

command virtualenv not found, did you mean:

command 'virtualenv' from deb virtualenv

Try: sudo apt install 

My bash shell is Ubuntu not debian. Not sure if that makes a difference.

I don't understand what  is. I don't understand why virtualenv
isn't found when it was successfully installed and every piece of
documentation I've found tells me to use that word or command.

The only reason I ask this forum is because the instructor of the video
hasn't responded to my email yet and this seems to be related to python
somehow although I'm a little foggy about that. If this is not the forum
please tell me where to go (be nice).

Thank you.

-- 
Roger Lea Scherer
623.255.7719

  *Strengths:*
   Input, Strategic,
Responsibility,

Learner, Ideation
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Numpy documentation

2018-10-04 Thread Roger Lea Scherer
I truly don't think I'm this stupid, but I can't even understand the fourth
paragraph of the numpy documentation.
https://docs.scipy.org/doc/numpy/user/quickstart.html says:

 In the example pictured below, the array has 2 axes. The first axis has a
length of 2, the second axis has a length of 3.
[[ 1., 0., 0.],
 [ 0., 1., 2.]]

(I think) I understand the 2 axes. [1,0,0] (I'm lazy and don't want to type
the periods) is one axis and [0,1,2] is the second axis. But then things
get goofy. The first axis has a length of 2. Is that because [1,0,0] and
[0,1,2] are counted as one axis? (I think) I understand the second axis has
a length of 3 because there are 3 elements within the [0,1,2] axis. Is that
correct? But why does the first axis have a length of 2? Because the second
zero doesn't count? Did they change the example and forgot to change the
text?

Thank you for your help as always.


-- 
Roger Lea Scherer
623.255.7719

  *Strengths:*
   Input, Strategic,
Responsibility,

Learner, Ideation
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running programs that import 3rd party packages installed using pip.

2018-10-04 Thread Roger B. Atkins
That's very helpful, thanks. After reading the Tutor information last
night, I wrote a little program I named sysinfo. The code run line by
line in a Spyder console yields:

In [3]: sys.path
Out[3]:
['',
 'C:\\Users\\rba21\\Anaconda3\\python36.zip',
 'C:\\Users\\rba21\\Anaconda3\\DLLs',
 'C:\\Users\\rba21\\Anaconda3\\lib',
 'C:\\Users\\rba21\\Anaconda3',
 'C:\\Users\\rba21\\Anaconda3\\lib\\site-packages',
 'C:\\Users\\rba21\\Anaconda3\\lib\\site-packages\\win32',
 'C:\\Users\\rba21\\Anaconda3\\lib\\site-packages\\win32\\lib',
 'C:\\Users\\rba21\\Anaconda3\\lib\\site-packages\\Pythonwin',
 'C:\\Users\\rba21\\Anaconda3\\lib\\site-packages\\IPython\\extensions',
 'C:\\Users\\rba21\\.ipython']

In [4]: sys.version
Out[4]: '3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC
v.1900 64 bit (AMD64)]'

In [5]: sys.platform
Out[5]: 'win32'

I'll have to do more research to figure out which folders I need to
add given that '\site-packages'
is already included, but at least I won't be looking at the wrong path variable.
On Thu, Oct 4, 2018 at 6:54 AM Mats Wichmann  wrote:
>
> On 10/03/2018 09:20 PM, Roger B. Atkins wrote:
> > System:  Windows 10, Anaconda, Python 3, Spyder3
> >
> > Problem: Running programs that import requests, pyperclip, bs4 and/or
> > other modules from 3rd party packages works fine within Spyder IDE,
> > but not from command line, or Win/R. The error message indicates no
> > such module. Therefore, my programs crash at the import statement. In
> > contrast, programs using built in modules work fine everywhere.
> > Questions: Which file needs to be found? Is this a path problem?
> >
> > Efforts to solve problem:  After making sure I had correctly typed the
> > module names, my second guess was that it is a path problem, so I used
> > win explorer to locate the module files. I also went to the command
> > line and used "pip show modname".
> > The search using win explorer revealed module files in multiple
> > directories, so part of the problem may be that I don't know which
> > file the import statement needs to be able to find.
> > Based on results using pip show modname, the modules were installed in:
> > Anaconda3\lib\site-packages.
> > In fact, as shown in Win Explorer, they are in sub folders under
> > \site-packages, and there are 'regular' py files as well as compiled
> > files. (I'm a beginner, and thought Python was interpreted?)
> >
> > I changed my system path variable to include:
> > C:\Users\rba21\Anaconda3\lib\site-packages# Result: same error message
> > C:\Users\rba21\Anaconda3\lib\site-packages\pyperclip  # Result: same
> > error message
> > I tried adding the sub folders down to __pycache__  but got the same
> > error message.
> >
> > I did some web searches, but didn't find anything that enabled me to
> > fix the problem.
>
> Write this simple program and run it from the "command line":
>
> import sys
> print(sys.path)
>
> those are the places Python will look for modules when importing. you
> can add to sys.path in your program, or if you define PYTHONPATH, its
> contents will show up in sys.path.
>
> if you now do the same thing in a program running inside Spyder, you'll
> probably see differences in sys.path.
>
> as Alan said, the system/user environment paths have nothing to do with
> Python's module importing.
>
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running programs that import 3rd party packages installed using pip.

2018-10-04 Thread Roger B. Atkins
Thanks! That helps. I'll have to go back to the drawing board, but
you've put me on the right "path".
On Thu, Oct 4, 2018 at 12:47 AM Alan Gauld via Tutor  wrote:
>
> On 04/10/18 04:20, Roger B. Atkins wrote:
> > System:  Windows 10, Anaconda, Python 3, Spyder3
> >
>
> > I changed my system path variable to include:
> > C:\Users\rba21\Anaconda3\lib\site-packages# Result: same error message
>
> When you say the "system path" do you mean the PYTHONPATH
> variable? It's PYTHONPATH not PATH that determines where
> Python looks for modules...
>
> Just a thought.
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Running programs that import 3rd party packages installed using pip.

2018-10-04 Thread Roger B. Atkins
System:  Windows 10, Anaconda, Python 3, Spyder3

Problem: Running programs that import requests, pyperclip, bs4 and/or
other modules from 3rd party packages works fine within Spyder IDE,
but not from command line, or Win/R. The error message indicates no
such module. Therefore, my programs crash at the import statement. In
contrast, programs using built in modules work fine everywhere.
Questions: Which file needs to be found? Is this a path problem?

Efforts to solve problem:  After making sure I had correctly typed the
module names, my second guess was that it is a path problem, so I used
win explorer to locate the module files. I also went to the command
line and used "pip show modname".
The search using win explorer revealed module files in multiple
directories, so part of the problem may be that I don't know which
file the import statement needs to be able to find.
Based on results using pip show modname, the modules were installed in:
Anaconda3\lib\site-packages.
In fact, as shown in Win Explorer, they are in sub folders under
\site-packages, and there are 'regular' py files as well as compiled
files. (I'm a beginner, and thought Python was interpreted?)

I changed my system path variable to include:
C:\Users\rba21\Anaconda3\lib\site-packages# Result: same error message
C:\Users\rba21\Anaconda3\lib\site-packages\pyperclip  # Result: same
error message
I tried adding the sub folders down to __pycache__  but got the same
error message.

I did some web searches, but didn't find anything that enabled me to
fix the problem.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] IDLE

2018-09-11 Thread Roger Lea Scherer
Can you direct me to where or how to update from Python 3.6.5 Shell, I
think it is also called IDLE 3.6.5, to Python 3.7 Shell? I looked at the
documentation which seems like there is another one, slightly improved.
I've downloaded Python 3.7, but can't figure out how to upgrade the
IDLE/Shell. And I can't for the life of me remember how I originally got
the Python 3.6.5 Shell.

Thank you

-- 
Roger Lea Scherer
623.255.7719

  *Strengths:*
   Input, Strategic,
Responsibility,

Learner, Ideation
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] localhosting

2018-09-06 Thread Roger Lea Scherer
Thank you all for your help. I am still chugging away at this problem. I've
switched to Windows PowerShell Version 5.1 since I can select, copy, and
paste more easily in PowerShell. (I can't figure out how to do that in
Anaconda and I get the same errors in PowerShell.)

I removed the "3" in "python3" and it works; along with moving the "www"
folder to where python resides. Thanks for the help.

So it appears the local host is running correctly, but when I run this code:

print("Hello World")

Chrome does not render and I get an error message in PowerShell:
127.0.0.1 - - [06/Sep/2018 11:22:46] "GET /cgi-bin/hello.py HTTP/1.1" 200 -
127.0.0.1 - - [06/Sep/2018 11:22:46] command:
C:\Users\Roger\AppData\Local\Programs\Python\Python37-32\python.exe -u
C:\Users\Roger\documents\roger\python\www\cgi-bin\hello.py ""
127.0.0.1 - - [06/Sep/2018 11:22:46] b'  File
"C:\\Users\\Roger\\documents\\roger\\python\\www\\cgi-bin\\hello.py", line
1\r\nprint ""\r\n ^\r\nSyntaxError: Missing
parentheses in call to \'print\'. Did you mean print("")?\r\n'
127.0.0.1 - - [06/Sep/2018 11:22:46] CGI script exit status 0x1

BUT when I run this code:
def fib(n):
if n < 2:
return n
return fib(n-1) + fib(n-2)

print(fib(15))

Chrome does not render but I DON'T get an error message, I get this:
127.0.0.1 - - [06/Sep/2018 11:33:30] "GET /cgi-bin/recursive%20fibonacci.py
HTTP/1.1" 200 -
127.0.0.1 - - [06/Sep/2018 11:33:30] command:
C:\Users\Roger\AppData\Local\Programs\Python\Python37-32\python.exe -u
"C:\Users\Roger\documents\roger\python\www\cgi-bin\recursive fibonacci.py"
""
127.0.0.1 - - [06/Sep/2018 11:33:30] CGI script exited OK

So I'm confused about 2 things:
1. Why does the one file cause an error in PowerShell (and Anaconda
actually) when it seems to be the same as the other file which appears to
run with no error, but just not render? and,
2. What am I missing: why won't it render since the instructions I have at
the very beginning of this email say, basically, this is all I have to do
to get it to render?

I know this second question is maybe a little bit outside this forum, but I
am struggling to make sense out of what little I know and, truly, this
forum seems the nicest and most helpful I've encountered.

Thank you as always.


On Thu, Aug 30, 2018 at 6:01 AM Mats Wichmann  wrote:

> On 08/30/2018 02:54 AM, Alan Gauld via Tutor wrote:
> > On 30/08/18 00:09, Roger Lea Scherer wrote:
> >> I'm trying to implement a local host. My instructions tell me to type
> the
> >> following command in the command line, make sure I'm in the "www" folder
> >
> > So this is not the folder where python3 is installed. (See below)
> >
> >> python3 -m http.server --cgi 8000
> >
> >> I'm running Anaconda in Windows 10. I get an error: 'python3' is not
> >> recognized as an internal or external command, operable program or batch
> >> file.
> >> But this is the folder that I thought Python 3.6 was in.
> >
> > you said you were in www which is not where Python should
> > be installed.
> >
> > It is likely that Python is not in your system PATH.
> > You need to find out where it is installed and add it.
> > In a standard Python install it would either be in
> > C:\PROGRAM FILES\PYTHON or
> > C:\PYTHON
> >
> > But Anaconda (version please?) could use its own path
> > such as
> >
> > C:\ANACONDA\PYTHON
> >
> >> So how do I correct this? I suspect python3 isn't in this folder. I
> know I
> >> have python3 because I run python3.6 shell practically every day.
> >
> > How do you run it?
> >>From a command line or via a menu/shortcut?
> >
> >> looked in the Program Files folder, came up empty as far as python is
> >> concerned, but I don't know where else to look?
>
> Several things that could help:
>
> you can ask python itself to tell you where it is, since you say python
> works for you.
>
> >>> import sys
> >>> print(sys.executable)
>
> the standard Windows python defaults to a "user install", so it could be
> in a place like
>
> {yourhomdirectory}/AppData/Local/Programs/Python
>
> Anaconda, as Alan says, likely puts it somewhere different.
>
> Python 3 isn't named python3 on Windows unless you take steps to make it
> so, it's just called python.  So modify your instructions accordingly.
>
> Also on Windows, if it was installed, there is a separate thing called
> the Python Launcher, which lets you run the command "py" which typically
&

[Tutor] localhosting

2018-08-30 Thread Roger Lea Scherer
I'm trying to implement a local host. My instructions tell me to type the
following command in the command line, make sure I'm in the "www" folder
(which I am and not a subfolder, although there is a subfolder "cgi-bin")
and then run this:
python3 -m http.server --cgi 8000
I'm running Anaconda in Windows 10. I get an error: 'python3' is not
recognized as an internal or external command, operable program or batch
file.
But this is the folder that I thought Python 3.6 was in.

I tried Windows PowerShell and received this error message: python3 : The
term 'python3' is not recognized as the name of a cmdlet, function, script
file, or operable program.
Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.

So how do I correct this? I suspect python3 isn't in this folder. I know I
have python3 because I run python3.6 shell practically every day. I've
looked in the Program Files folder, came up empty as far as python is
concerned, but I don't know where else to look?

Or if this is not the correct forum, can you please (re)direct me to the
correct one?

Thank you.


-- 
Roger Lea Scherer
623.255.7719

  *Strengths:*
   Input, Strategic,
Responsibility,

Learner, Ideation
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Accessing a tuple of a dictionary's value

2018-08-22 Thread Roger Lea Scherer
So I'm trying to divide fractions, technically I suppose integers. So, for
instance, when the user inputs a 1 as the numerator and a 2 as the
denominator to get the float 0.5, I want to put the 0.5 as the key in a
dictionary and the 1 and the 2 as the values of the key in a list {0.5: [1,
2]}, hoping to access the 1 and 2 later, but not together. I chose a
dictionary so the keys won't duplicate.

I can't find anything in StackOverflow or Python documentation specifically
about this. They talk about accessing a list or a tuple or a dictionary,
but not when the value is a tuple or list.

 I've tried:
fractions.values([0])
which gives a TypeError: values() takes no arguments (1 given)

I've tried
fractions.values()[0]
which gives a TypeError: 'dict_values' object does not support indexing

Both of these errors sort of make sense to me, but I can't find a way to
access the 1 or the 2 in the dictionary key:value pair {0.5: [1, 2]}

Thank you for your help.

-- 
Roger Lea Scherer
623.255.7719

  *Strengths:*
   Input, Strategic,
Responsibility,

Learner, Ideation
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Removing duplicates

2018-08-02 Thread Roger Lea Scherer
I'm trying to get a list of tuples to be a float, a numerator, and a
denominator for all the fractions: halves, thirds, fourths etc up to
ninths. 1/2 returns the same float as 2/4, 3/6, 4/8. I would like to keep
only the 1/2. When I try (line 18) to "pop"  from the list I get a "TypeError:
integer argument expected, got float". When I try (line 18)  to "remove"
from the list, nothing happens: nothing is removed and I do not receive an
error message.

What do you think is a good way to solve this?

Thank you as always.

import math

fractions = [(0, 0, 0)]

for i in range(1, 10):
for j in range(1, 10):
if i < j:
x = i/j
if x not in fractions:
fractions.append((x, i, j))
sortedFrac =  sorted(fractions)

print(sortedFrac)

for i in range(len(sortedFrac)):
try:
if sortedFrac[i][0] == sortedFrac[i-1][0]: # so if the float equals
the previous float
sortedFrac.pop(sortedFrac[i][0])   # remove the second
float
else:
sortedFrac.append(sortedFrac[i][0])
except ValueError:
continue


-- 
Roger Lea Scherer
623.255.7719

  *Strengths:*
   Input, Strategic,
Responsibility,

Learner, Ideation
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Recursion

2018-06-18 Thread Roger Lea Scherer
My foggy understanding of recursion is probably the reason I can't figure
this out. When turtle draws this program there is an orange line in the
green which I would prefer not to have. I've tried all I could think of,
but can't get the orange line to go away, or maybe more accurately, not to
be drawn.

The program goes to the end of the recursion and then starts drawing? which
seems wrong, because the trunk of the tree is drawn first. Maybe: How does
it know to draw the second orange line? and how does it know when to stop
with only two branches from the trunk?

Thank you as always.
-
import turtle

def tree(branchLen, width, t):
if branchLen > 5:
t.pensize(width)
t.forward(branchLen)
t.right(20)
tree(branchLen-15, width-5, t)
t.left(40)
tree(branchLen-15, width-5, t)
t.pencolor("orange")
t.right(20)
t.backward(branchLen)
t.pencolor("green")

def main():
t = turtle.Turtle()
myWin = turtle.Screen()
t.speed(0)
t.left(90)
t.up()
t.backward(100)
t.down()
t.color("green")
tree(75, 20, t)
myWin.exitonclick()

main()

-- 
​
Roger Lea Scherer
623.255.7719

  *Strengths:*
   Input, Strategic,
​ ​
Responsibility,
​​
Learner, Ideation
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iteration issues

2018-06-07 Thread Roger Lea Scherer
I've given up again. I've tried the python documentation, I've tried to
implement the above suggestions, I've tried the translate thing with a
table that I did not include this time because I couldn't get it to work,
I've looked at StackOverflow, Quora and another website, so many things
seem so promising, but I just can't get them to work nor figure out why
they won't. I've started from scratch again.

**
import string

gettysburg =
open("C:/Users/Roger/Documents/GitHub/LaunchCode/gettysburg.txt", "r")

puncless = ""
for char in gettysburg:
if char in string.punctuation:
gettysburg.replace(char, "")
else:
puncless += char
print(puncless)

**

The "puncless" part works fine, except it does not replace the punctuation
like I expect and want.

Thank you for all your help already, but I need some more if you have any.
:) Thanks.

On Sat, May 12, 2018 at 12:40 AM, Peter Otten <__pete...@web.de> wrote:

> Neil Cerutti wrote:
>
> > punctuation_removal_table = str.maketrans({c: None for c in
> > string.punctuation})
>
> Alternative spellings:
>
> >>> from string import punctuation
> >>> (str.maketrans({c: None for c in punctuation})
> ...  == str.maketrans(dict.fromkeys(punctuation))
> ...  == str.maketrans("", "", punctuation))
> True
>
>
> _______
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Roger Lea Scherer
623.255.7719
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Turtle drawing

2018-06-05 Thread Roger Lea Scherer
I give up again. Here's my code which gives no error, but draws something
that looks sort of like a dinosaur. I've included the first few lines of
the text file mystery so you can see the format I received from the
instructions.

Please help. Thank you.

*Mystery excerpt*
UP
-218 185
DOWN
-240 189
-246 188
-248 183
-246 178
**

# Draw a picture based on the txt file mystery

# When UP go to the next line, read x,y coordinates, go to that point
# When DOWN go to the next line, read x,y coordinates, go to that point and
continue until UP

import turtle


wn = turtle.Screen()   # Set up the window and its attributes
wn.bgcolor("beige")
hadir = turtle.Turtle() # create hadir
hadir.color('orange')
hadir.speed(0)
datums = open("C:/Users/Roger/Documents/GitHub/LaunchCode/mystery.txt", "r")

for aline in datums:
splitted = aline.split()
try:
coords = [int(i) for i in splitted]
x = coords[0]
y = coords[1]
hadir.goto(x, y)
except:
while splitted == "UP":
hadir.pu()
while splitted == "DOWN":
hadir.pd()

turtle.exitonclick()

-- 
Roger Lea Scherer
623.255.7719
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Iteration issues

2018-05-10 Thread Roger Lea Scherer
Hello, again.

I want to count words in a text file. If a word repeats I want to increase
the count by 1; if the word is new to the dictionary, I want to add the
word to the dictionary. Everything works like I would like and expect,
except for it only adds the last word of each line to the dictionary. What
am I missing?

import string

file_name = 'oxford.txt'
wordset = {}
with open(file_name, 'r') as f:
for line in f:
sentence = line.strip()
sentence = sentence.strip(string.punctuation)
print(sentence)
sentence = sentence.lower()
word_list = sentence.strip()
word_list = word_list.split(' ')

for i in range(len(word_list)):
word_list[i] = word_list[i].strip(string.punctuation)
print(word_list)

if word_list[i] in wordset:
wordset[word_list[i]] += 1
else:
wordset[word_list[i]] = 1
print(wordset)

The output is: (I included only the first four lines)

The Project Gutenberg EBook of Advice to a Young Man upon First Going to
['the', 'project', 'gutenberg', 'ebook', 'of', 'advice', 'to', 'a',
'young', 'man', 'upon', 'first', 'going', 'to']
{'to': 1}
Oxford, by Edward Berens
['oxford', 'by', 'edward', 'berens']
{'to': 1, 'berens': 1}

['']
{'to': 1, 'berens': 1, '': 1}
This eBook is for the use of anyone anywhere at no cost and with
['this', 'ebook', 'is', 'for', 'the', 'use', 'of', 'anyone', 'anywhere',
'at', 'no', 'cost', 'and', 'with']
{'to': 1, 'berens': 1, '': 1, 'with': 1}

Thank you as always.

-- 
Roger Lea Scherer
623.255.7719
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] beginning encryption

2018-04-19 Thread Roger Lea Scherer
I am absolutely stumped. I've tried a number of different scenarios and
copied the answer more than I like, but I still can't figure this out. I
don't want to copy the answer verbatim because then I won't learn.

I'm doing the beginning cipher, mix up the letters routine. I get the
entire Gettysburg address with no alterations in this form of the code (and
a few others I've tried). I do not receive any error, but I expect the
character in the Gettysburg address to change to the index position in the
encryption variable.

What am I not getting?

Thank you as always.



address = """Four score and seven years ago our fathers brought forth on
this continent, a new nation,
conceived in Liberty, and dedicated to the proposition that all men are
created equal.
Now we are engaged in a great civil war, testing whether that nation, or
any nation so conceived
and so dedicated, can long endure. We are met on a great battle-field of
that war. We have come
to dedicate a portion of that field, as a final resting place for those who
here gave their lives that
that nation might live. It is altogether fitting and proper that we should
do this.
But, in a larger sense, we can not dedicate -- we can not consecrate -- we
can not hallow -- this ground.
The brave men, living and dead, who struggled here, have consecrated it,
far above our poor power
to add or detract. The world will little note, nor long remember what we
say here, but it can never
forget what they did here. It is for us the living, rather, to be dedicated
here to the unfinished work
which they who fought here have thus far so nobly advanced. It is rather
for us to be here dedicated
to the great task remaining before us -- that from these honored dead we
take increased devotion
to that cause for which they gave the last full measure of devotion -- that
we here highly resolve
that these dead shall not have died in vain -- that this nation, under God,
shall have a new birth
of freedom -- and that government of the people, by the people, for the
people, shall not perish
from the earth."""

alphabet = "abcdefghijklmnopqrstuvwxyz"
encryption = "nopqrstuvwxyzabcdefghijklm"


def encryptor(address):
encrypted = ""
for char in address:
if char != alphabet:
encrypted += char
else:
pos = alphabet.index(char)
    encrypted += encryption[pos]
print(encrypted)

encryptor(address)


-- 
Roger Lea Scherer
623.255.7719
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Return problems

2018-04-07 Thread Roger Lea Scherer
So I've examined my educational material, I've perused the python
documentation and for the life of me I can't figure out why return doesn't
print a result in the IDE. I use print, the program acts as expected. What
am I missing?

import math

from decimal import Decimal

def findHypot(a, b):
c = math.sqrt((a ** 2) + (b ** 2))
if c == (round(c)):
return round(c)
else:
return round(c, 4)

findHypot(3, 4)

from the IDE:

= RESTART: C:\Users\Roger\Documents\GitHub\LaunchCode\hypotenuse.py
=
>>>

Thank you as always.

-- 
Roger Lea Scherer
623.255.7719
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Turtle color question

2018-03-29 Thread Roger Lea Scherer
I've tried everything I can think of but cannot get the pencolor to change.
(Although the arrow drawing the boxes changes color.) I've placed it in
places I didn't even think it would work. The arrow draws what looks like
the boxes I expect, but the color looks the same as the background. So I
assigned a variable and printed that variable which says None. See:

 RESTART: C:/Users/Roger/AppData/Local/Programs/Python/Python36/turtle
square draw.py
None
>>>

Removing " color = " doesn't change the outcome. I hope this adequately
explains things.Thanks, again.

​import turtle

def drawSquare(t, sz):
"""Get turtle t to draw a square of sz side"""
t.pu()
t.forward(sz*2)

for i in range(4):
t.forward(sz)
t.left(90)


wn = turtle.Screen()
wn.bgcolor("blue")

alex = turtle.Turtle()
color = alex.pencolor("darkgreen")
print(color)

def main():
for i in range(4):
drawSquare(alex,20)

main()

wn.exitonclick()
​

-- 
Roger Lea Scherer
623.255.7719
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Pi approximation

2018-03-28 Thread Roger Lea Scherer
In one of my lessons I am asked to compare approximations for pi. I got
everything to work properly and my attempt is successful and matches
Python's approximation up to 15 digits to the right of the decimal, but I
suspect I can do this programmatically rather than the repetitious way I
did.

I tried "for i in range(10):"; then I tried "c += c" so it would be a sum.
Those attempts did not work. I tried math.fsum and though the documentation
says it is for iterables I could not get it to work as I desired. I
received an error that said TypeError: 'float' object is not iterable

I included all the code so I wouldn't neglect any you might need. Can you
help again?

Thank you.

# compare various approximations of pi
import math
import random

# simplest estimate
a = 22/7
print(a)

# next simplest
b = 355/113
print(b)

# from wikipedia:
# In 1910, the Indian mathematician Srinivasa Ramanujan found several
rapidly converging infinite series
c = (2*math.sqrt(2)/9801) * (((math.factorial(4*0))*(1103+26390*0)) /
((math.factorial(0)**4)*(396**(4*0
d = (2*math.sqrt(2)/9801) * (((math.factorial(4*1))*(1103+26390*1)) /
((math.factorial(1)**4)*(396**(4*1
e = (2*math.sqrt(2)/9801) * (((math.factorial(4*2))*(1103+26390*2)) /
((math.factorial(2)**4)*(396**(4*2
f = (2*math.sqrt(2)/9801) * (((math.factorial(4*3))*(1103+26390*3)) /
((math.factorial(3)**4)*(396**(4*3
g = (2*math.sqrt(2)/9801) * (((math.factorial(4*4))*(1103+26390*4)) /
((math.factorial(4)**4)*(396**(4*4
h = (2*math.sqrt(2)/9801) * (((math.factorial(4*5))*(1103+26390*5)) /
((math.factorial(5)**4)*(396**(4*5
i = (2*math.sqrt(2)/9801) * (((math.factorial(4*6))*(1103+26390*6)) /
((math.factorial(6)**4)*(396**(4*6
j = (2*math.sqrt(2)/9801) * (((math.factorial(4*7))*(1103+26390*7)) /
((math.factorial(7)**4)*(396**(4*7
k = (2*math.sqrt(2)/9801) * (((math.factorial(4*8))*(1103+26390*8)) /
((math.factorial(8)**4)*(396**(4*8
l = (2*math.sqrt(2)/9801) * (((math.factorial(4*9))*(1103+26390*9)) /
((math.factorial(9)**4)*(396**(4*9
m = c + d + e + f + g + h + i + j + k + l
print(1/m)

print(math.pi)


-- 
Roger Lea Scherer
623.255.7719
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Polygon fill in turtle

2018-03-27 Thread Roger Lea Scherer
I looked at Stackoverflow, followed, but could not succeed. I want to fill
the polygon with a different color than the pen color. When I print out the
filler it is the correct color, but the actual fill is not. Here it is:
(tada!)

# create a user-defined polygon
import turtle


wn = turtle.Screen()
hadir = turtle.Turtle()
hadir.speed(8)

sides = int(input("Please enter the number of sides of a polygon you want
drawn: "))
length = int(input("How long would you like each side? "))
outlineColor = input("What color would you like for the outline?")
filler = input("And what color would you like to fill it with? ")

hadir.begin_fill()
hadir.color(outlineColor)
print(filler)
for i in range(sides):
hadir.forward(length)
hadir.left(360 / sides)
hadir.up()
hadir.end_fill()

Thanks, as always.

-- 
Roger Lea Scherer
623.255.7719
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Turtle Issues

2018-03-06 Thread Roger Lea Scherer
I know I don't have to apologize, but I am so independent I hate asking for
help and you guys and gals have been so helpful that now that I'm stuck
again I'm sorry I have to. I've looked on StackOverflow and followed their
advice (which I can't make work) and went to the python/turtle
documentation which I tried to follow, but can't seem to make work either.

All I want to do (famous last words) is randomize the color of the pen when
the ciphers are created, but when the ciphers are created, the color
remains black. The comments below colormode are things I've tried as well.
I include all the code in case you want to run the program.

So if you could please help like you do, that would be great and greatly
appreciated. Thank you.



from turtle import *
import re
import random


# use turtle to draw ciphers of the Cistercian monks

digits = input("Please enter an integer less than 10,000 greater than 0:  ")

r = random.randrange(0, 255)
g = random.randrange(0, 255)
b = random.randrange(0, 255)

# ensure input is only digits
p = re.compile(r'^\d+$')
m = p.match(digits)
if m:
print(digits)
m = digits
#digits = input("Please enter an integer less than 10,000 greater
than 0:  ")
else:
print("No match")

colormode(255)
##reddish = random.randrange(255)
##greenish = random.randrange(255)
##bluish = random.randrange(255)
##pencolor(reddish, greenish, bluish)
# pencolor(random.randrange(255), random.randrange(255),
random.randrange(255))
pencolor(r, g, b)

mode("logo")   # resets turtle heading to north
speed(0)
ht()
fd(100)


# if statements for the ones position
if digits[-1] == "1":
pu()
goto(0, 100)
seth(90)
pd()
fd(35)

if digits[-1] == "2":
pu()
goto(0, 65)
seth(90)
pd()
fd(35)

if digits[-1] == "3":
pu()
goto(0, 100)
seth(135)
pd()
fd(50)

if digits[-1] == "4":
pu()
goto(0, 65)
seth(45)
pd()
fd(50)

if digits[-1] == "5":
pu()
goto(0, 100)
seth(90)
pd()
fd(35)
rt(135)
fd(50)

if digits[-1] == "6":
pu()
goto(30, 100)
seth(180)
pd()
fd(35)

if digits[-1] == "7":
pu()
goto(0, 100)
seth(90)
pd()
fd(35)
rt(90)
fd(35)

if digits[-1] == "8":
pu()
goto(0, 65)
seth(90)
pd()
fd(35)
lt(90)
fd(35)

if digits[-1] == "9":
pu()
goto(0, 100)
seth(90)
pd()
fd(35)
rt(90)
fd(35)
rt(90)
fd(35)

# if statements for the tens position
if digits[-2:-1] == "1":
pu()
goto(0, 100)
seth(-90)
pd()
fd(35)

if digits[-2:-1] == "2":
pu()
goto(0, 65)
seth(-90)
pd()
fd(35)

if digits[-2:-1] == "3":
pu()
goto(0, 100)
seth(-135)
pd()
fd(50)

if digits[-2:-1] == "4":
pu()
goto(0, 65)
seth(-45)
pd()
fd(50)

if digits[-2:-1] == "5":
pu()
goto(0, 100)
seth(-90)
pd()
fd(35)
lt(135)
fd(50)

if digits[-2:-1] == "6":
pu()
goto(-30, 100)
seth(180)
pd()
fd(35)

if digits[-2:-1] == "7":
pu()
goto(0, 100)
seth(-90)
pd()
fd(35)
lt(90)
fd(35)

if digits[-2:-1] == "8":
pu()
goto(0, 65)
seth(-90)
pd()
fd(35)
rt(90)
fd(35)

if digits[-2:-1] == "9":
pu()
goto(0, 100)
seth(-90)
pd()
fd(35)
lt(90)
fd(35)
lt(90)
fd(35)

# if statments for the hundreds position
if digits[-3:-2] == "1":
pu()
goto(0, 0)
seth(90)
pd()
fd(35)

if digits[-3:-2] == "2":
pu()
goto(0, 35)
seth(90)
pd()
fd(35)

if digits[-3:-2] == "3":
pu()
goto(0, 0)
seth(45)
pd()
fd(50)

if digits[-3:-2] == "4":
pu()
goto(0, 35)
seth(135)
pd()
fd(50)

if digits[-3:-2] == "5":
pu()
goto(0, 0)
seth(90)
pd()
fd(35)
lt(135)
fd(50)

if digits[-3:-2] == "6":
pu()
goto(30, 0)
seth(0)
pd()
fd(35)

if digits[-3:-2] == "7":
pu()
goto(0, 0)
seth(90)
pd()
fd(35)
lt(90)
fd(35)

if digits[-3:-2] == "8":
pu()
goto(0, 35)
seth(90)
pd()
fd(35)
rt(90)
fd(35)

if digits[-3:-2] == "9":
pu()
goto(0, 0)
seth(90)
pd()
fd(35)
lt(90)
fd(35)
lt(90)
fd(35)

# if statments for the thousands position
if digits[-4:-3] == "1":
pu()
goto(0, 0)
seth(-90)
pd()
fd(35)

if digits[-4:-3] == "2":
pu()
goto(0, 35)
seth(-90)
pd()
fd(35)

if digits[-4:-3] == "3":
pu()
goto(0, 0)
seth(-35)
pd()
fd(50)

if digits[-4:-3] == "4":
pu()
goto(0, 35)
seth(-135)
pd()
fd(50)

if digits[-4:-3] == "5":
pu()
goto(0, 0)
seth(-90)
pd()
fd(35)
rt(135)
fd(50)

if digits[-4:-3] == "6":
pu()
goto(-30, 0)
seth(0)
pd()
fd(35)

if digits[-4:-3] == "7":
pu()
goto(0, 0)
seth(-90)
pd()
fd(35)
rt(90)
fd(35)

if digits[-4:-3

[Tutor] Another question, dictionaries

2018-03-02 Thread Roger Lea Scherer
I'm trying to finish chapter 5 in my book and it has to do with
dictionaries and creating simple games. We need a pool of points and the
ability to exchange point between the pool and each of the, what I call,
attributes of Strength, Health, Wisdom, and Dexterity. I got only to the
first option and I'm stuck on how to get the points to change
"permanently". The program will run well for option 1 (I haven't got to the
rest of the options), but the next time I run the program it goes back to
the original configuration. Did I do everything right, but I just need to
write to a file, and that's what the problem is? or what?

I've reread the chapter, I've gone on stackoverflow and thegeekstuff.com,
I've thought about it for at least a day and I just can't figure out what
the problem is. Please help?

# Character creator program for role playing

pool = 30

attributes = {"Strength": 0, "Health": 0, "Wisdom": 0, "Dexterity": 0}

print("You have", pool, "points")
print("""
You can apply them to your Strength, Health, Wisdom, or Dexterity.

Press:

0 to Quit
1 to apply points to Strength
2 to apply points to Health
3 to apply points to Wisdom
4 to apply points to Dexterity
5 to apply points from Strength to your pool
6 to apply points from Health to your pool
7 to apply points from Wisdom to your pool
8 to apply points from Dexterity to your pool
""")

choice = input("Choice: ")
print(attributes.get("Strength"))

if choice == "0":
print("Good-bye.")
input("\n\nPress enter to exit.")

elif choice == "1":
strengthChoice = input("How many points would you like to transfer from
pool to Strength?: ")
print(strengthChoice)
attributes["Strength"] += int(strengthChoice)
print(attributes.get("Strength"))
pool -= int(strengthChoice)
print(pool)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Regex not working as desired

2018-02-26 Thread Roger Lea Scherer
  The first step is to input data and then I want to check to make sure
there are only digits and no other type of characters. I thought regex
would be great for this. The program works great, but no matter what I
enter, the regex part does the same thing. By same thing I mean this:

 RESTART: C:\Users\Roger\Documents\GitHub\ciphers\cipher1.py

Please enter an integer less than 10,000 greater than 0:  4jkk33
No match
>>>
 RESTART: C:\Users\Roger\Documents\GitHub\ciphers\cipher1.py

Please enter an integer less than 10,000 greater than 0:  4k33
No match
>>>
 RESTART: C:\Users\Roger\Documents\GitHub\ciphers\cipher1.py

Please enter an integer less than 10,000 greater than 0:  4jjk4
No match
>>>
==== RESTART: C:\Users\Roger\Documents\GitHub\ciphers\cipher1.py

Please enter an integer less than 10,000 greater than 0:  4334
No match

So I don't know what I'm doing wrong. The cipher will still draw, but I
want to return an "error message" in this case print("No match"), but it
does it every time, even when there are only digits; that's not what I
want. Please help. Below is my code:

from turtle import *
import re

# use turtle to draw ciphers of the Cistercian monks

digits = input("Please enter an integer less than 10,000 greater than 0:  ")

""" ensure input is no other characters than digits
sudocode: if the input has anything other than digits
 return digits  """

#def digit_check(digits):
# I thought making it a function might h
p = re.compile(r'[^\D]')
m = p.match(digits)
if m:
print("No match")
else:
print(digits)
digits = m

#digit_check(digits)

mode("logo")   # resets turtle heading to north
speed(0)
ht()
fd(100)

# if statements for the ones position
if digits[-1] == "1":
pu()
goto(0, 100)
seth(90)
pd()
fd(35)

if digits[-1] == "2":
pu()
goto(0, 65)
seth(90)
pd()
fd(35)

if digits[-1] == "3":
pu()
goto(0, 100)
seth(135)
pd()
fd(50)

if digits[-1] == "4":
pu()
goto(0, 65)
seth(45)
pd()
fd(50)

if digits[-1] == "5":
pu()
goto(0, 100)
seth(90)
pd()
fd(35)
rt(135)
fd(50)

if digits[-1] == "6":
pu()
goto(30, 100)
seth(180)
pd()
fd(35)

if digits[-1] == "7":
pu()
goto(0, 100)
seth(90)
pd()
fd(35)
rt(90)
fd(35)

if digits[-1] == "8":
pu()
goto(0, 65)
seth(90)
pd()
fd(35)
lt(90)
fd(35)

if digits[-1] == "9":
pu()
goto(0, 100)
seth(90)
pd()
fd(35)
rt(90)
fd(35)
rt(90)
fd(35)

# if statements for the tens position
if digits[-2:-1] == "1":
pu()
goto(0, 100)
seth(-90)
pd()
fd(35)

if digits[-2:-1] == "2":
pu()
goto(0, 65)
seth(-90)
pd()
fd(35)

if digits[-2:-1] == "3":
pu()
goto(0, 100)
seth(-135)
pd()
fd(50)

if digits[-2:-1] == "4":
pu()
goto(0, 65)
seth(-45)
pd()
fd(50)

if digits[-2:-1] == "5":
pu()
goto(0, 100)
seth(-90)
pd()
fd(35)
lt(135)
fd(50)

if digits[-2:-1] == "6":
pu()
goto(-30, 100)
seth(180)
pd()
fd(35)

if digits[-2:-1] == "7":
pu()
goto(0, 100)
seth(-90)
pd()
fd(35)
lt(90)
fd(35)

if digits[-2:-1] == "8":
pu()
goto(0, 65)
seth(-90)
pd()
fd(35)
rt(90)
fd(35)

if digits[-2:-1] == "9":
pu()
goto(0, 100)
seth(-90)
pd()
fd(35)
lt(90)
fd(35)
lt(90)
fd(35)

# if statments for the hundreds position
if digits[-3:-2] == "1":
pu()
goto(0, 0)
seth(90)
pd()
fd(35)

if digits[-3:-2] == "2":
pu()
goto(0, 35)
seth(90)
pd()
fd(35)

if digits[-3:-2] == "3":
pu()
goto(0, 0)
seth(45)
pd()
fd(50)

if digits[-3:-2] == "4":
pu()
goto(0, 35)
seth(135)
pd()
fd(50)

if digits[-3:-2] == "5":
pu()
goto(0, 0)
seth(90)
pd()
fd(35)
lt(135)
fd(50)

if digits[-3:-2] == "6":
pu()
goto(30, 0)
seth(0)
pd()
fd(35)

if digits[-3:-2] == "7":
pu()
goto(0, 0)
seth(90)
pd()
fd(35)
lt(90)
fd(35)

if digits[-3:-2] == "8":
pu()
goto(0, 35)
seth(90)
pd()
fd(35)
rt(90)
fd(35)

if digits[-3:-2] == "9":
pu()
goto(0, 0)
seth(90)
pd()
fd(35)
lt(90)
fd(35)
lt(90)
fd(35)

# if statments for the thousands position
if digits[-4:-3] == "1":
pu()
goto(0, 0)
seth(-90)
pd()
fd(35)

if digits[-4:-3] == "2&

[Tutor] xlrd has no attribute

2018-01-11 Thread Roger Lea Scherer
I'm trying to learn how open a xls file in python. I thought this would be
easier. I've read on a blog this code and seen it on other websites. I
thought I'd try it out. I'm on Windows 10 with python 3.6.4.

import xlrd

def open_file(path):
"""
Open and read an Excel file
"""
book = xlrd.open_workbook(path)

# print number of sheets
print(book.nsheets)

# print sheet names
print(book.sheet_names())

# get the first worksheet
first_sheet = book.sheet_by_index(0)

# read a row
print(first_sheet.row_values(0))

# read a cell
cell = first_sheet.cell(0,0)
print(cell)
print(cell.value)

open_file("C:/Users/Roger/Documents/Roger/archive/area codes.xls")

But I get an error:

Traceback (most recent call last):
  File "C:\Users\Roger\Documents\Roger\Python\xlrd.py", line 1, in 
import xlrd
  File "C:\Users\Roger\Documents\Roger\Python\xlrd.py", line 26, in 
open_file("C:/Users/Roger/Documents/Roger/archive/area codes.xls")
  File "C:\Users\Roger\Documents\Roger\Python\xlrd.py", line 7, in open_file
book = xlrd.open_workbook(path)
AttributeError: module 'xlrd' has no attribute 'open_workbook'

I've looked at http://www.lexicon.net/sjmachin/xlrd.html and it looks like
it should be ok. I've looked at Stack overflow and I have the
opening/closing parentheses appropriately placed to make it a method.

Can you help, please?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Floating decimal question

2017-12-18 Thread Roger Lea Scherer
This is my first time in this "forum", please be patient I will do my best.

As I was going through a book and came across this challenge, I did what I
believe was a success. And I know there are ways of making the decimal
place be limited to 2 places, but my question is more of understanding why
the following happened.

This is the code I wrote in python:

bill = float(input("What is the price of the bill?: "))
tip15 = bill*1.15
tip20 = bill*1.20

print("Bill plus 15% gratuity is " + str(tip15))
print("Bill plus 20% gratuity is " + str(tip20))



This is the result I got after I ran the code in an IDE (obviously) and
then entered 29.99 in the first line:

What is the price of the bill?: 29.99
Bill plus 15% gratuity is 34.4884995
Bill plus 20% gratuity is 35.988



My question is why does the 15% gratuity go so far beyond the decimal place
when really there should only be 4 places because of multiplication rules,
you know, and I do understand sometimes things work behind the scenes that
you don't see, but on the 20% gratuity it gives the "right" answer? So I
guess I'm just asking why did this happen like this?

Thank you.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] python problems on android

2014-01-03 Thread Roger
Hi. I wrote a few python programs and had them running on my phone up to last 
september.
Haven't had time to work on them again till now.
Only now, they... don't work !
Not sure why and its very frustrating.

one of the errors is in response to an input request like this

g = input ("type h to use last settings ") 

stops the program with this

File , line1, in 
NameError: name 'h' is not defined

after I entered h

Will I have to abandon using SL4A and Python and switch to using android/java ? 





___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] sqlite search

2013-01-25 Thread Roger
Hello,

I am very new to python. Wrote a small program to use on my android phone using 
pickle/shelve to access  data.
That worked fine but i realised it would be better to use sqlite as a database 
to more easily modify the data.
I havent got a clue about sqlite, have a book but cant find the answer
My problem is this. i can access data by putting characters to search for in 
the program but i want it to be a variable that i can search for characters i 
input from keypad.
I am guessing its a syntax problem?
At the moment this works to search for everything beginning with A

sql = "SELECT * FROM plants WHERE genus LIKE 'A%'";

cursor.execute(sql);

slt =cursor.fetchone();


What i really need is to search for everything beginning with two letters from 
an input command___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sqlite search syntax

2013-01-18 Thread Roger Shaw
Hello,  
I am very new to python. 

Wrote a small program to use on my android phone 
using pickle/shelve to access  data. 

That worked fine but i realised it would be better to use sqlite as a 
database to more easily modify the data. 

I havent got a clue about sqlite, have a book but cant find the 
answer 

My problem is this. 

I can access data by putting characters to search for 
into the program but i want it to be a variable string that i can search for.

Specificaly a couple of letters  i 
input from keypad.



At the moment this works to search for everything beginning with A  
sql = "SELECT * FROM plants WHERE genus LIKE 'A%'";  
cursor.execute(sql);  
slt =cursor.fetchone();   
What i really need is to search for everything beginning with two letters 
from an input command.

As in A is a variable that could be Bl or An or someother two letter combination


Hope you can help. 

Roger___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] ADO with python 2.6 without additional installs

2012-04-10 Thread Bakkestuen Roger
Hi
I'm struggling with finding a way to access and query an MSAccess base in an 
organisation with a very standardised environment.
Python 2.6 is available and Office 2010.

Is there a way to access and query trough for instance ADO without having to 
install the Win32 package?
Any suggestions or even sample code?


Best regards
Roger Bakkestuen

Norwegian Public Roads Administration
Eastern Region - Geodata
Post adress: Statens vegvesen Region øst, Postboks 1010, 2605 LILLEHAMMER
Office adress: Industrigaten 17, LILLEHAMMER
Phone: +47 61271236  Mobile: +47 94833636  e-mail: 
roger.bakkest...@vegvesen.no<mailto:roger.bakkest...@vegvesen.no>
www.vegvesen.no<http://www.vegvesen.no/>  e-mail: 
firmapost-...@vegvesen.no<mailto:firmapost-...@vegvesen.no>

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python function to know the path of the program in execution * *

2010-02-05 Thread Rohit Roger$
ok..

On Fri, Feb 5, 2010 at 6:23 PM, Daniel Sarmiento wrote:

>  Junk Score: 2 out of 10 (below your Auto Allow 
> threshold<https://www.boxbe.com/mail-screening>)
> | Approve sender <https://www.boxbe.com/anno?tc=1530328725_1435846689> | Block
> sender <https://www.boxbe.com/anno?tc=1530328725_1435846689&disp=b> | Block
> domain <https://www.boxbe.com/anno?tc=1530328725_1435846689&disp=b&dom>
>
>
>
>  Date: Fri, 5 Feb 2010 17:43:37 +0530
>> From: Spoorthi 
>> To: "Rohit Roger$" 
>> Cc: tutor 
>> Subject: Re: [Tutor] python function to know the path of the program
>>in  execution *
>> Message-ID:
>><6c9f52051002050413o57bd76bax7ac5986b17304...@mail.gmail.com>
>> Content-Type: text/plain; charset="iso-8859-1"
>>
>> The below data(in blue) made me converge upon sys.path[0] for this
>> particular problem...I dont think it returns None if a Python script is
>> used. Can anyone please correct me if I am wrong
>>
>> *As initialized upon program startup, the first item of this list,
>> path[0],
>> is the directory containing the script that was used to invoke the Python
>> interpreter. If the script directory is not available (e.g. if the
>> interpreter is invoked interactively or if the script is read from
>> standard
>> input), path[0] is the empty string, which directs Python to search
>> modules
>> in the current directory first. Notice that the script directory is
>> inserted
>> before the entries inserted as a result of PYTHONPATH.*
>>
>> On Fri, Feb 5, 2010 at 5:38 PM, Rohit Roger$ 
>> wrote:
>>
>>
>>> sys.path[0] returns none
>>>
>>>
>>>
>>> On Fri, Feb 5, 2010 at 5:36 PM, Spoorthi  wrote:
>>>
>>>  sys.path[0] should be serving the purpose effectively I guess
>>>>
>>>>
>>>> On Fri, Feb 5, 2010 at 5:29 PM, Rohit Roger$ >>> >wrote:
>>>>
>>>>  Answer :
>>>>> >>> import sys
>>>>>
>>>>>> rohit = sys.argv[0]
>>>>>>>> print rohit
>>>>>>>>
>>>>>>>  it returns the name of the path
>>>>>
>>>>> On Fri, Feb 5, 2010 at 4:13 PM, David Hutto >>>> >wrote:
>>>>>
>>>>>   Junk Score: 2 out of 10 (below your Auto Allow threshold<
>>>>>> https://www.boxbe.com/mail-screening>)
>>>>>> | Approve sender <https://www.boxbe.com/anno?tc=1529381613_418589136>
>>>>>> |
>>>>>> Block sender<
>>>>>> https://www.boxbe.com/anno?tc=1529381613_418589136&disp=b>| Block
>>>>>> domain <https://www.boxbe.com/anno?tc=1529381613_418589136&disp=b&dom
>>>>>> >
>>>>>>
>>>>>>
>>>>>>
>>>>>> --- On *Fri, 2/5/10, nikunj badjatya *
>>>>>> wrote:
>>>>>>
>>>>>>
>>>>>> From: nikunj badjatya 
>>>>>> Subject: [Tutor] python function to know the path of the program in
>>>>>> execution
>>>>>> To: tutor@python.org
>>>>>> Date: Friday, February 5, 2010, 5:08 AM
>>>>>>
>>>>>> Hi ,
>>>>>> Is there any python function to know the path of the python program
>>>>>> under execution.?
>>>>>> If someone executes a program , he should come to know the path of the
>>>>>> program..!!
>>>>>> ex. suppose a user ABC is running prog.py which is in ~ directory, the
>>>>>> user currently is in XYZ directory.
>>>>>> [ a...@localhost XYZ ]$ python ~/prog.py
>>>>>> The program's location is ~/prog.py
>>>>>>
>>>>>> This should be the outcome of the program.
>>>>>>
>>>>>> I tried with os.getcwd()
>>>>>> os.getcwd() will return /path/to/folder/XYZ.
>>>>>>
>>>>>> Any suggestions?
>>>>>>
>>>>>> Thanks,
>>>>>> Nikunj Badjatya
>>>>>> Bangalore, India
>>>>>>
>>>>>> -Inline Attachment Follows-
>>>>>>
>>>>>> ___
>>>>>> Tutor maillist  -  Tutor@python.org<
>>>>>> http://mc/com

Re: [Tutor] Variable: From input and output

2010-02-05 Thread Rohit Roger$
Answer:
Here is the code :

>>> firstname = raw_input("\n Enter your first name : ")
>>> lastname = raw_input("\n Enter your last name : ")
>>> print (" Printing Your Complete name.")
>>> print firstname + " " + lastname

Regards,
Rohit

On Fri, Feb 5, 2010 at 6:04 PM, Kent Johnson  wrote:

> On Thu, Feb 4, 2010 at 5:39 PM, ssiverling  wrote:
> >
> >
> > I uploaded a file.  I know it's not very impressive.
>
> Where did you upload it?
>
> For short programs you can just include them in your email.
>
> Also, please don't top-post, and please subscribe to the list.
>
> Kent
> >
> >
> > Kent Johnson wrote:
> >>
> >> On Thu, Feb 4, 2010 at 1:19 PM, ssiverling 
> wrote:
> >>
> >>> So I have been working on this example for a little while.  I looked
> for
> >>> the
> >>> answer before posting.  I tried to use two raw inputs, then use
> >>> sys.stdout.write, to add them together.  However I think I might need
> to
> >>> use
> >>> a variable.  Any help would be appreciated.  Thank you in advance.
> >>
> >> What have you done so far? If you show us some code we can better help
> >> you.
> >>
> >> Kent
> >> ___
> >> Tutor maillist  -  Tutor@python.org
> >> To unsubscribe or change subscription options:
> >> http://mail.python.org/mailman/listinfo/tutor
> >>
> >>
> > http://old.nabble.com/file/p27460922/psy psy
> > --
> > View this message in context:
> http://old.nabble.com/Variable%3A-From-input-and-output-tp27457364p27460922.html
> > Sent from the Python - tutor mailing list archive at Nabble.com.
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> >
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python function to know the path of the program in execution *

2010-02-05 Thread Rohit Roger$
it tell the path upto the python file..

On Fri, Feb 5, 2010 at 5:43 PM, Spoorthi  wrote:

> The below data(in blue) made me converge upon sys.path[0] for this
> particular problem...I dont think it returns None if a Python script is
> used. Can anyone please correct me if I am wrong
>
> *As initialized upon program startup, the first item of this list, path[0],
> is the directory containing the script that was used to invoke the Python
> interpreter. If the script directory is not available (e.g. if the
> interpreter is invoked interactively or if the script is read from standard
> input), path[0] is the empty string, which directs Python to search
> modules in the current directory first. Notice that the script directory is
> inserted before the entries inserted as a result of PYTHONPATH.*
>
>
> On Fri, Feb 5, 2010 at 5:38 PM, Rohit Roger$ wrote:
>
>>
>> sys.path[0] returns none
>>
>>
>>
>> On Fri, Feb 5, 2010 at 5:36 PM, Spoorthi  wrote:
>>
>>> sys.path[0] should be serving the purpose effectively I guess
>>>
>>>
>>> On Fri, Feb 5, 2010 at 5:29 PM, Rohit Roger$ wrote:
>>>
>>>> Answer :
>>>>  >>> import sys
>>>> >>> rohit = sys.argv[0]
>>>> >>> print rohit
>>>>  it returns the name of the path
>>>>
>>>> On Fri, Feb 5, 2010 at 4:13 PM, David Hutto wrote:
>>>>
>>>>>  Junk Score: 2 out of 10 (below your Auto Allow 
>>>>> threshold<https://www.boxbe.com/mail-screening>)
>>>>> | Approve sender <https://www.boxbe.com/anno?tc=1529381613_418589136>| 
>>>>> Block
>>>>> sender <https://www.boxbe.com/anno?tc=1529381613_418589136&disp=b> | Block
>>>>> domain <https://www.boxbe.com/anno?tc=1529381613_418589136&disp=b&dom>
>>>>>
>>>>>
>>>>>
>>>>> --- On *Fri, 2/5/10, nikunj badjatya *wrote:
>>>>>
>>>>>
>>>>> From: nikunj badjatya 
>>>>> Subject: [Tutor] python function to know the path of the program in
>>>>> execution
>>>>> To: tutor@python.org
>>>>> Date: Friday, February 5, 2010, 5:08 AM
>>>>>
>>>>> Hi ,
>>>>> Is there any python function to know the path of the python program
>>>>> under execution.?
>>>>> If someone executes a program , he should come to know the path of the
>>>>> program..!!
>>>>> ex. suppose a user ABC is running prog.py which is in ~ directory, the
>>>>> user currently is in XYZ directory.
>>>>> [ a...@localhost XYZ ]$ python ~/prog.py
>>>>> The program's location is ~/prog.py
>>>>>
>>>>> This should be the outcome of the program.
>>>>>
>>>>> I tried with os.getcwd()
>>>>> os.getcwd() will return /path/to/folder/XYZ.
>>>>>
>>>>> Any suggestions?
>>>>>
>>>>> Thanks,
>>>>> Nikunj Badjatya
>>>>> Bangalore, India
>>>>>
>>>>> -Inline Attachment Follows-
>>>>>
>>>>> ___
>>>>> Tutor maillist  -  Tutor@python.org<http://mc/compose?to=tu...@python.org>
>>>>> To unsubscribe or change subscription options:
>>>>> http://mail.python.org/mailman/listinfo/tutor
>>>>>
>>>>>
>>>>> I think this is what you want:
>>>>>
>>>>> >>> import sys
>>>>> >>> sys.argv[0]
>>>>> 'C:\\Python26\\testingscripts\\lowdir.py'
>>>>> >>>
>>>>>
>>>>> David
>>>>>
>>>>>
>>>>>
>>>>> ___
>>>>> Tutor maillist  -  Tutor@python.org
>>>>> To unsubscribe or change subscription options:
>>>>> http://mail.python.org/mailman/listinfo/tutor
>>>>>
>>>>>
>>>>
>>>> ___
>>>> Tutor maillist  -  Tutor@python.org
>>>> To unsubscribe or change subscription options:
>>>> http://mail.python.org/mailman/listinfo/tutor
>>>>
>>>>
>>>
>>>
>>> --
>>> Spoorthi
>>>
>>
>>
>
>
> --
> Spoorthi
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python function to know the path of the program in execution *

2010-02-05 Thread Rohit Roger$
sys.path[0] returns none


On Fri, Feb 5, 2010 at 5:36 PM, Spoorthi  wrote:

> sys.path[0] should be serving the purpose effectively I guess
>
>
> On Fri, Feb 5, 2010 at 5:29 PM, Rohit Roger$ wrote:
>
>> Answer :
>>  >>> import sys
>> >>> rohit = sys.argv[0]
>> >>> print rohit
>>  it returns the name of the path
>>
>> On Fri, Feb 5, 2010 at 4:13 PM, David Hutto wrote:
>>
>>>  Junk Score: 2 out of 10 (below your Auto Allow 
>>> threshold<https://www.boxbe.com/mail-screening>)
>>> | Approve sender <https://www.boxbe.com/anno?tc=1529381613_418589136> | 
>>> Block
>>> sender <https://www.boxbe.com/anno?tc=1529381613_418589136&disp=b> | Block
>>> domain <https://www.boxbe.com/anno?tc=1529381613_418589136&disp=b&dom>
>>>
>>>
>>>
>>> --- On *Fri, 2/5/10, nikunj badjatya * wrote:
>>>
>>>
>>> From: nikunj badjatya 
>>> Subject: [Tutor] python function to know the path of the program in
>>> execution
>>> To: tutor@python.org
>>> Date: Friday, February 5, 2010, 5:08 AM
>>>
>>> Hi ,
>>> Is there any python function to know the path of the python program under
>>> execution.?
>>> If someone executes a program , he should come to know the path of the
>>> program..!!
>>> ex. suppose a user ABC is running prog.py which is in ~ directory, the
>>> user currently is in XYZ directory.
>>> [ a...@localhost XYZ ]$ python ~/prog.py
>>> The program's location is ~/prog.py
>>>
>>> This should be the outcome of the program.
>>>
>>> I tried with os.getcwd()
>>> os.getcwd() will return /path/to/folder/XYZ.
>>>
>>> Any suggestions?
>>>
>>> Thanks,
>>> Nikunj Badjatya
>>> Bangalore, India
>>>
>>> -Inline Attachment Follows-
>>>
>>> ___
>>> Tutor maillist  -  Tutor@python.org<http://mc/compose?to=tu...@python.org>
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>>
>>> I think this is what you want:
>>>
>>> >>> import sys
>>> >>> sys.argv[0]
>>> 'C:\\Python26\\testingscripts\\lowdir.py'
>>> >>>
>>>
>>> David
>>>
>>>
>>>
>>> ___
>>> Tutor maillist  -  Tutor@python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
>
> --
> Spoorthi
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python function to know the path of the program in execution *

2010-02-05 Thread Rohit Roger$
Answer :
 >>> import sys
>>> rohit = sys.argv[0]
>>> print rohit
 it returns the name of the path

On Fri, Feb 5, 2010 at 4:13 PM, David Hutto  wrote:

>  Junk Score: 2 out of 10 (below your Auto Allow 
> threshold)
> | Approve sender  | Block
> sender  | Block
> domain 
>
>
>
> --- On *Fri, 2/5/10, nikunj badjatya * wrote:
>
>
> From: nikunj badjatya 
> Subject: [Tutor] python function to know the path of the program in
> execution
> To: tutor@python.org
> Date: Friday, February 5, 2010, 5:08 AM
>
> Hi ,
> Is there any python function to know the path of the python program under
> execution.?
> If someone executes a program , he should come to know the path of the
> program..!!
> ex. suppose a user ABC is running prog.py which is in ~ directory, the user
> currently is in XYZ directory.
> [ a...@localhost XYZ ]$ python ~/prog.py
> The program's location is ~/prog.py
>
> This should be the outcome of the program.
>
> I tried with os.getcwd()
> os.getcwd() will return /path/to/folder/XYZ.
>
> Any suggestions?
>
> Thanks,
> Nikunj Badjatya
> Bangalore, India
>
> -Inline Attachment Follows-
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
> I think this is what you want:
>
> >>> import sys
> >>> sys.argv[0]
> 'C:\\Python26\\testingscripts\\lowdir.py'
> >>>
>
> David
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python and Abaqus

2009-10-20 Thread Paul Roger Leinan

Hi!
Referring to 
http://mail.python.org/pipermail/tutor/2008-November/065270.html


Would you be able to send me these python examples to?

Regards
Paul Leinan

--

Paul Roger Leinan
PhD Student
Department of Structural Engineering - Biomechanics -
Norwegian University of Science and Technology (NTNU)
Web: www.ntnu.no/biomechanics <http://www.ntnu.no/biomechanics/>
Email: paul.lei...@ntnu.no <mailto:paul.lei...@ntnu.no>
Phone: (+47) 481 81 457
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Allow only one instance of a process

2009-05-19 Thread Roger
On Sunday 17 May 2009 21:54:54 Kent Johnson wrote:
> On Sat, May 16, 2009 at 10:26 PM, Sylvain Ste-Marie
>
>  wrote:
> > I'm currently writing a script to batch convert video for my psp
> >
> > It basically looks into a folder for video and launch ffmpeg:
> >
> > ffmpeg -i "videoname" -f psp -r 29.97 -b 768k -ar 24000 -ab 64k -s
> > 368x208 "videoname.mp4"
> >
> > my idea is basically to check for pid but how do i do that?
>
> Look at psutil:
> http://code.google.com/p/psutil/
>
> But you will have a race condition if you do something like this:
>
> if ffmpeg is not running:
>   start ffmpeg
>
> A file lock is a better solution. Google 'python file lock' for recipes.
>

As a Java programmer just starting with Python, this answer surprised me. I
would've been googling for the Python equivalent of the Singleton pattern. 
I guess it's going to take longer than I thought to get my head around the
differences. 

With the lock file solution, if your program crashes, don't you have to 
undertake some form of manual/automated recovery to remove any left
over lock files?

Regards
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] [Web] Using pyCrypto - pyscard

2009-01-24 Thread Olivier Roger
Hello,

I have a question concerning the use of python to make web application.
I don't know if it is possible. I would like to create an applet capable of
using the client smardcard (with pyscard/pyCrypto module) reader to read and
display the contained data on the page.

I already have a simple python application that does it. My question is the
following: Is it possible to port it into an applet?

Thank in advance,

Olivier
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Program Specification Request

2008-01-16 Thread Roger Maxwell
Hi all:
   1st post! Have been lurker 4 some time. Thanks to
all.
   I am new to Python and a former DOS Clipper
programmer.
   I would like to learn and teach my 2 girls a mini
database GUI program in Python and 
   They are Girl Scouts (and advanced MS & HS
students)
   It is, almost, (19 January 2008)GS cookie time in
CA.
   S.
   
   Question(s):
   Q01:  Is this a 'reasonable' first project?
   Q02:  We can use either MAC or WinXP but which? Or
both?
   Q03:  Is this the appropriate forum?

thanx.


  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] curses delwin functionality?

2005-12-29 Thread Roger Merchberger
Rumor has it that Bernd Prager may have mentioned these words:

[snippety]

> # curses.delwin(s) <-- that doesn't exist :-/

I've *only* done curses in python, so quite often I don't know the C 
analogue, but try:

curses.endwin()

I'm not sure if that's exactly what your looking for, but if not, try here:

http://heather.cs.ucdavis.edu/~matloff/Python/PyCurses.pdf

Google is your friend! ;-)

HTH,
Roger "Merch" Merchberger

--
Roger "Merch" Merchberger  --  SysAdmin, Iceberg Computers
[EMAIL PROTECTED]

Hi! I am a .signature virus.  Copy me into your .signature to join in!

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Does a module for DirectFB exist?

2005-11-11 Thread Roger Merchberger
Rumor has it that Roger Merchberger may have mentioned these words:
>DirectFB is short for Direct Frame Buffer, and allows access to a graphical
>frame buffer system in *nix (and I think maybe MacOSX) from a text prompt
>without going through X.
>
>Anyone know of a module to access this through Python? I've googled for it,
>but didn't know if anyone here knew about something along these lines.

Yea, I like talking to myself... This is just fer the archives anywho...

The DirectFB can make use of the SDL which does access the hardware 
directly, and I did find a python module for libSDL, but it looked like it 
hadn't been supported for 3-4 years... according to the webpage, all of the 
functionality of that module was built into a module called PyGame.

PyGame makes direct access to the hardware possible through SDL or DirectFB 
(altho for some reason the DirectFB component couldn't compile on my 
system. :-/ ) and with other SDL modules supports blitting graphics and TTF 
fonts directly to the framebuffer.

It took a little work getting it working, but now I can print text & 
graphics of any size to the framebuffer without needing X to do it (and X 
is kinda limited when you're talking 200-pixel text rendering in an 
xterm... PyGame does it easily as it doesn't have xterm's restraints.).

Anyway, I hope this helps someone else out there...

Laterz,
Roger "Merch" Merchberger

--
Roger "Merch" Merchberger   | "Profile, don't speculate."
SysAdmin, Iceberg Computers | Daniel J. Bernstein
[EMAIL PROTECTED]  |

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Does a module for DirectFB exist?

2005-11-01 Thread Roger Merchberger
DirectFB is short for Direct Frame Buffer, and allows access to a graphical 
frame buffer system in *nix (and I think maybe MacOSX) from a text prompt 
without going through X.

Anyone know of a module to access this through Python? I've googled for it, 
but didn't know if anyone here knew about something along these lines.

Thanks,
Roger "Merch" Merchberger

--
Roger "Merch" Merchberger   | A new truth in advertising slogan
SysAdmin, Iceberg Computers | for MicroSoft: "We're not the oxy...
[EMAIL PROTECTED]  | ...in oxymoron!"

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] removal

2005-08-03 Thread Roger Sell
Please remove from the Tutor recipient list.

Thanks,

Roger Sell

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Corrupt files

2005-08-02 Thread Roger Merchberger
Rumor has it that geon may have mentioned these words:
>Øyvind napsal(a):
>
> >Hello.
> >
> >I have created a program that automatically downloads some files I need.
> >It can be .zip, .jpg, .mpg or .txt. However, a lot of the time urlretrieve
> >downloads the file, gives no error, but the downloaded file is corrupted.
> >I use a simple check for the size of the file. If it is way too small, I
> >automatically remove it.
> >
>
>remove it and try to download it again, lets say , 3times until you get
>correct copy...

Or, depending on it's extension, try to open the newly downloaded file with 
the corresponding Python extension, i.e. (.jpg|.gif|.png) try to open with 
PIL[1], .zip files with the python zipfile module, etc. I *think* there's 
modules for .mpgs and maybe .avi's... but .txt files might be tough to 
authenticate, as there's no actual 'file format.'

This python pseudocode might explain more:

=-=-=-=-=-=-= snip here =-=-=-=-=-=-=

def openzip(filename):
 import zipfile
 try:
   filebuf = zipfile.open(filename)
 except:
   return "Error 99: cannot open file; corrupted zipfile."

 filebuf.close()
 return None

if __name__ == '__main__':

 if filename[:-4] == '.zip':
 retcode = openzip(filename)
 if retcode != None:
 print "Corrupt File - Try to download again!"

=-=-=-=-=-=-= snip here =-=-=-=-=-=-=

Just put an 'openzip' or 'openjpg' type of function for each type of file 
you'll need to authenticate.

[[ This code will *not* run -- it certainly won't run in Eudora (where it's 
being typed), so it's only for showing the general idea... YMMV, UAYOR, 
etc. ;-) ]]

Hope this helps,
Roger "Merch" Merchberger

[1] PIL == Python Image Library; it will open almost any type of static 
graphic image available.

--
Roger "Merch" Merchberger   | "Bugs of a feather flock together."
sysadmin, Iceberg Computers |   Russell Nelson
[EMAIL PROTECTED]  |

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building an SQL query

2005-06-02 Thread Roger Merchberger
Rumor has it that Alan G may have mentioned these words:

>Hmm, I dunno ADOpy but assume it somehow miraculously turns your data
>set into a dictionary of some sort?

I dunno ADOpy, but the pg module for PostgreSQL can return a list of 
dictionaries from a query.

 >>> import pg
 >>> pg.set_defuser('example')
 >>> pg.set_defpasswd('example')
 >>> pg.set_defbase('spam')
 >>> pgpasswd = pg.DB()

 >>> pgpasswd.query('select dtg, classc, helo from ips limit 3;').dictresult()

[{'helo': 'veda.cz', 'dtg': '2005-03-30', 'classc': '85.39.122'},
  {'helo': 'ck336290-a.dokku1.fr.home.nl', 'dtg': '2005-03-30', 'classc': 
'217.123.211'},
  {'helo': 'keymaster.com', 'dtg': '2005-03-30', 'classc': '220.73.88'}]

*** output edited slightly with carriage returns ***

>  How it guesses which order the
>SELECT will return the fields is a mystery to me,

It's a mystery to some RDBs as well, IIRC with SQL there's no 'default 
behavior' -- if it's not defined, it can be spit out in any order it 
chooses; prolly depends on the implementation.

It might also matter how the indices & primary keys are set up as to what 
comes out first...

>  but maybe it has
>knowledge of the Postgres hashing function or somesuch.

With dictionaries, it doesn't matter nearly so much. ;-)

The ease with which data can be I/O'd thru PostgreSQL with Python is one of 
the main factors of my dumping Perl for it; I can spend more time diddling 
with the data than I need to do making the proggies run.
;-)

HTH,
Roger "Merch" Merchberger

--
Roger "Merch" Merchberger   | "Bugs of a feather flock together."
sysadmin, Iceberg Computers |   Russell Nelson
[EMAIL PROTECTED]  |

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] better resolution on time.sleep()?

2005-05-26 Thread Roger Merchberger
Rumor has it that Alan G may have mentioned these words:

> > I'm running an application that has a polling loop to check a serial
>port
> > for certain signals, and on my laptop I can get about 6700 samples
>per
> > second, which (of course) consumes 100% CPU; which may impact
>battery life.
>
>Consuming 100% CPU won't make much difference, the CPU is running all
>the time anyway (when its not asleep).

Not mine... my laptop runs a Crusoe processor, and it can automatically 
scale itself from 300Mhz to 933Mhz. It's called "LongRun" technology, and 
it works quite well, too. On my extended battery at "near idle" ... say, 
playing Spider, I get 5+ hours of battery life (and the battery's 2 years 
old, just like the laptop). Running the program at full tilt, I get just 
over 2 hours (but admittedly, it's scanning my USB->RS232 dongle, and I 
don't know how much current that may take... However, it's not 
transmitting, so it shouldn't be an overly huge amount.) I can run more 
tests if anyone's interested, but...

Since the first Pentium (and possibly '486s) the CPU could put itself in a 
wait state to conserve CPU cycles that weren't being used -- and "wake 
itself up" automatically when needed. WinNT 4.0 and newer (and most *nixen) 
could use that, altho it didn't make *as much* difference for thermal or 
power aspects back then; the ability was there mainly for multiprocessor 
applications. Now they've improved it for both thermal and power usage 
functions as well.

>  What will consume batteries much
>faster is if you are accessing hardware such as disk or modem or other 
>power hungry devices.

I would only get about 1.5 hours (when the battery was new) compiling my 
LinuxFromScratch -- 100% CPU, HD getting hammered and snagging packages off 
of the CDROM... yea, the battery (and external charger) got quite a workout 
those few weeks... ;-)

>I've never tried in Python but can you use select()?
>I've used it in C for short duration intervals.

Never used it yet (altho I saw references that Python's time.sleep() 
actually *uses* select instead of usleep/nanosleep.

Not being a C hacker, I don't know much about it, but I'll check it out. 
Thanks!

=-=-=

I was also looking into trying the usleep implementation in wxPython -- 
well, I couldn't get the rascal compiled on my old Linux From Scratch 
version 4 installation (my main working Linux for that laptop) no matter 
what I turned off in .configure... I guess I should prioritize my LFS6 
install a bit higher. ;-)

Thanks one and all, and back to "quiet mode" I go... ;-)
Roger "Merch" Merchberger
--

Roger "Merch" Merchberger   | "Profile, don't speculate."
SysAdmin, Iceberg Computers | Daniel J. Bernstein
[EMAIL PROTECTED]  |

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] better resolution on time.sleep()?

2005-05-23 Thread Roger Merchberger
Rumor has it that Roger Merchberger may have mentioned these words:

Yea, yea, I'm replying my own message you'll see why later! ;-)

>Rumor has it that [EMAIL PROTECTED] may have mentioned these words:

> >I just did some experimenting ... I am running ActiveState Python 2.4.1 
> under
> >Windows XP / cygwin.
>
>I'm running under Linux From Scratch, book 4.0, kernel 2.4.29.

I downloaded and compiled Python 2.4.1 this evening, and the granularity of 
sleep hasn't changed on my system... maybe it's a kernel limitation? Hrm...

Despite my pitiful C knowledge, I found a code snippet I modified to make a 
command-line "msleep" command which sleeps for 1 millisecond & exits, and 
called that with an os.system('msleep') call. The best I could get then is 
around 32 samples for second, so that seemed "marginally less efficient" 
calling my msleep command thru the OS compared to the "realtime usleep" 
function I downloaded earlier to run on Python 2.2.2. The realtime package 
wouldn't compile with Python 2.4.1 (not that it did me much good before... ;-).

=-=-=

I'm downloading the source to wxPython now, there is a wx.usleep function 
in there. As I mentioned, it seems a bit'o'overkill to me, but what the 
heck, in for a penny, in for a pound, eh? ;^>

I'll let y'all know how it turns out...

Laterz,
Roger "Merch" Merchberger

--
Roger "Merch" Merchberger   | Anarchy doesn't scale well. -- Me
[EMAIL PROTECTED] |
SysAdmin, Iceberg Computers

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] better resolution on time.sleep()?

2005-05-23 Thread Roger Merchberger
Rumor has it that [EMAIL PROTECTED] may have mentioned these words:
>Quoting Roger Merchberger <[EMAIL PROTECTED]>:
>
> > I really only need between 500 and 1000 samples per second, but as the
> > smallest sleep available normally is time.sleep(.01) -- which brings my
> > samples/sec to a nice 100; but I need it a little faster.
>
>Where did you find that out?

Imperical testing -- I put in values smaller than .01, yet never got more 
than 100 samples per second. ;-) I then googled around and I saw a few 
other people found the same thing; but with no resolutions.

I *can* post some ugly code if necessary...

>I just did some experimenting ... I am running ActiveState Python 2.4.1 under
>Windows XP / cygwin.

I'm running under Linux From Scratch, book 4.0, kernel 2.4.29.

[code snippage]

>The first test is fairly consistent with time.sleep(0.001) doing what you
>expect.  The second is a bit puzzling to me, though...

Yea, seems to be a bit of weirdness there... Hrm

Anyway, maybe I'll go snag 2.4.x and see what that does for me...

Laterz,
Roger "Merch" Merchberger

--
Roger "Merch" Merchberger   | Anarchy doesn't scale well. -- Me
[EMAIL PROTECTED] |
SysAdmin, Iceberg Computers

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] better resolution on time.sleep()?

2005-05-23 Thread Roger Merchberger
I'm running an application that has a polling loop to check a serial port 
for certain signals, and on my laptop I can get about 6700 samples per 
second, which (of course) consumes 100% CPU; which may impact battery life. 
BTW, I'm running Python 2.2.2 on my laptop... not had a need to upgrade yet.

I really only need between 500 and 1000 samples per second, but as the 
smallest sleep available normally is time.sleep(.01) -- which brings my 
samples/sec to a nice 100; but I need it a little faster.

I found this:

http://freshmeat.net/projects/rtsched/

which is supposed to bring real-time scheduling to Python (which the docs 
say is dangerous if used incorrectly) and also implementations of 
msleep/usleep/nanosleep.

I downloaded it, compiled it, installed it, and popped in an import rtsched 
at the top and rtsched.msleep(1) where the time.sleep(.01) used to go... 
and now I get around 50 samples per second. I tried the usleep(1) and 
nanosleep(1) and the same thing happens. The rtsched implementation *is* 
working, as I can put in rtsched.msleep(100) and my samples/sec drops to 10.

I'm guessing there's so much overhead to calling rtsched that it's b0rking 
up the works. :-/

Anyone know of:

1) a working millisleep/microsleep implementation for python 2.2+?

-or-

2) will upgrading to a newer version of Python get me what I need?
[[ I looked thru the "New in 2.4" dox and nothing I needed was listed...]]

I've googled (off and on for more than a few days) and searched the 
archives, and came up empty so far...

This isn't life or death by any means... My laptop known for long battery 
life, so everything should be OK as is, but why grind the CPU if it's not 
necessary, eh? ;-) Just a niggling little thing that's been on the back of 
my mind...

[[ Oh, I found a reference to wxwindows that might have something that 
could work, but I was hoping for a little less overkill... my app barely 
uses ncurses. ]]

Thanks!
Roger "Merch" Merchberger

--
Roger "Merch" Merchberger  --  SysAdmin, Iceberg Computers
[EMAIL PROTECTED]

Hi! I am a .signature virus.  Copy me into your .signature to join in!

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] counting no of words

2005-01-20 Thread Roger Merchberger
Rumor has it that Bill Mill may have mentioned these words:
[snip]
Once you're connected to a word document, you'll have to figure out
what the command to count the words in the document is, but that's
just a matter of recording a macro in word where you count the words,
then repeating it in python.
Another option would be to write the python program from within 
OpenOffice.org if it's available -- it has facilities of opening and 
accessing word documents as well.

I'd help you with that, but I'm on linux.
Most things I do are on Linux as well; but the OpenOffice solution should 
work equally well on either platform.

HTH,
Roger "Merch" Merchberger
--
Roger "Merch" Merchberger  --  SysAdmin, Iceberg Computers
[EMAIL PROTECTED]
Hi! I am a .signature virus.  Copy me into your .signature to join in!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] O.T.

2004-12-29 Thread Roger Merchberger
Rumor has it that Bob Gailer may have mentioned these words:
[snip]
Programmed in more languages than I care to recall. The more 
interesting/arcane include
Motorola 8080?  Assembler and Machine language
Yup - that sure is arcane -- It's either an Intel 8080 or a Motorola 6800. 
;-)
Me:
37, married 12 years, 3 kids (2 personally crafted ;-) one dog, and live in 
one of the oldest cities in the US.

Been interested in computers since '76, but didn't get a chance to really 
work on them until '84. First computer: Tandy Color Computer 2.

My computer languages:
APL, COBOL, Basic09 (which is 1/2 Pascal), umpteen other dialects of Basic 
(for most 8-bitters on up), Logo, Moto6800/6809 Assembler & Machine 
Language, Atmel AVR Assembler, Pascal, Lisp (mostly AutoLisp), JCL, 
ColdFusion, some C, some PHP, enough Java to know I don't much care for 
it... and was a devout Perl follower until I found Python.

If it isn't listed above, I prolly forgot I ever learned it! ;-)
Interests: Old computers, still photography, cooking, I'm starting to teach 
myself woodworking, and if you consider it an interest: construction. My 
house is ancient, and sucks. I'm interested in making it "suck less," 
therefore, I'm interested in construction. ;-)

Happy Hollydaze,
Roger "Merch" Merchberger
--
Roger "Merch" Merchberger  --  SysAdmin, Iceberg Computers
[EMAIL PROTECTED]
Hi! I am a .signature virus.  Copy me into your .signature to join in!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What am I doing wrong...

2004-12-23 Thread Roger Merchberger
Rumor has it that Ken Stevens may have mentioned these words:
I am a elative new comer to python. I wrote the following test
snippet.
#!/usr/bin/env python
def main ():
play_test()
def play_test ():
print "Hi! -- in play test"
When I do "python test.py" absolutely nothing happens.
Correct.
I expect it to do the print statement.
Thanks in advance for your help.
You defined functions, but not the main code of the program, therefore it 
does nothing.

Appended to your program, you need this:
### This defines where the actual program starts...
if __name__ == '__main__':
main()
### Now the program is done. ;-)
Hope this Helps!
Roger "Merch" Merchberger
--
Roger "Merch" Merchberger   | Anarchy doesn't scale well. -- Me
[EMAIL PROTECTED] |
SysAdmin, Iceberg Computers
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] silly question

2004-12-22 Thread Roger Merchberger
Rumor has it that Jason Child may have mentioned these words:
## I've got a silly question.
###
P1 = "prefix1"
P2 = "prefix2"
def my_func(list, items):
   s = 0
   out = ""
   for i in range(len(list)):
   if s == 0:
   p = P1
   s = 1
   else:
   p = P2
   s = 0
   for j in range(len(items)):
   out += p +items[j]
   return out

If my input was:
list = ["car list 1","car list 2"]
items = ["torino","mustang","elantra"]
for output I get:
prefix1torinoprefix1mustangprefix1elantraprefix1torinoprefix1mustangprefix1elantra
when I expect:
prefix1torinoprefix1mustangprefix1elantraprefix2torinoprefix2mustangprefix2elantra
Why not just do this:
###
prefixes = ["prefix1" , "prefix2" ]
def my_func(list, items):
   out = ""
   for prefixloop in prefixes:
 for itemloop in items:
   out += prefixloop + itemloop
   return out

It's what's called a 'nested loop' - and that way if you had to add a 3rd 
prefix, it would "just work" instead of having to add yet another variable 
to the loop you'd designed.

By the way, other than getting the length of 'list' you don't use anything 
in that list. Another thing (which might also be a problem in your code) 
using 'list' as a variable name is not a good idea, as it's a reserved 
word, if I'm not mistaken. Consider this snippet:

Python 2.2.2 (#1, Feb 24 2003, 19:13:11)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> q = (1,2,3)
>>> print list(q)
[1, 2, 3]
Hope this helps,
Roger "Merch" Merchberger
--
Roger "Merch" Merchberger   | "Profile, don't speculate."
SysAdmin, Iceberg Computers | Daniel J. Bernstein
[EMAIL PROTECTED]  |
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] Popen? or something else

2004-12-22 Thread Roger Merchberger
Rumor has it that Ertl, John may have mentioned these words:
Roger,
I have been doing it the Pythonic way (that is why I have no idea about how
Popen works) but I need to make sure (the systems guys called me on it)  I
use the same dtg as everyone else...it is possible (has not happened yet in
20 years) it could be set to something else.
Is the example you gave using the new 2.4 Popen?  It looks like the older
popen.  I can get the older popen to work but not Popen.
My newest is 2.3.3 - I had no idea they modified popen for 2.4, but try 
this:
dtg_s = Popen("/path/to/dtg", shell=True, stdout=PIPE).stdout
If I've read the dox for 2.4 correctly, this has almost a fair chance of 
working... ;-) I cannot test this, however, as I don't have 2.4. (Glad I 
didn't upgrade, either -- I have several programs that rely on the present 
os.popen() )

here's a good page with how the new Popen works:
http://www.python.org/peps/pep-0324.html
with examples on how to replace os.popen[234]() and os.system().
HTH,
Roger "Merch" Merchberger
--
Roger "Merch" Merchberger  --  SysAdmin, Iceberg Computers
[EMAIL PROTECTED]
Hi! I am a .signature virus.  Copy me into your .signature to join in!
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Popen? or something else

2004-12-22 Thread Roger Merchberger
Rumor has it that Ertl, John may have mentioned these words:
All,
I hate to ask this but I have just installed 2.4 and I need to get some info
from a subprocess (I think that is correct term).
At the Linux command line if I input dtg I get back a string representing a
date time group.  How do I do this in Python?  I would think Popen but I
just don't see it.
It could, but there's also a better (IMHO), 'pythonic' way, something like 
this:

def gettoday():
 import time
 today = time.strftime('%Y%m%d%H',time.localtime(time.time()))
 return (today)
$ dtg
2004122212
If you wanted to use popen, it would look rather like this:
import os
dtg_s = os.popen("/path/to/dtg").readlines()[0]
But this may use more system resources (spawning child shells & whatnot) 
than doing everything internally with the time module in Python.

HTH,
Roger "Merch" Merchberger
--
Roger "Merch" Merchberger   | A new truth in advertising slogan
SysAdmin, Iceberg Computers | for MicroSoft: "We're not the oxy...
[EMAIL PROTECTED]  | ...in oxymoron!"
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor