Re: [Tutor] tar a directory

2016-11-04 Thread Alan Gauld via Tutor
On 03/11/16 17:56, Bill Nolf wrote: > Test 4 > > archive = tarfile.open("test.tgz", "a:gz") > archive.add=(dirarchive, arcname="test") > archive.close() > > Create a gzip file called test.tgz in the current directory, which is close > but no cigar > What I would like is the following gzip file:

[Tutor] Fwd: Re: tar a directory

2016-11-04 Thread Alan Gauld via Tutor
Always use reply-all or reply-list when responding to tutor posts == The archive file changes each time so I need to set a variable based on the changing directory Sent from my iPhone > On Nov 4, 2016, at 5:54 AM, Alan Gauld via Tutor <tutor@python.org&

Re: [Tutor] Python code

2016-11-01 Thread Alan Gauld via Tutor
On 01/11/16 21:28, Haley Sandherr wrote: > Hello, I am new to python and need help with this question: What kind of help? What exactly do you find difficult? > > Compose a function odd ( ) Can you define a function? Any function? > that takes three bool arguments Can you define a function

Re: [Tutor] implementing sed - termination error

2016-11-01 Thread Alan Gauld via Tutor
On 02/11/16 00:18, bruce wrote: > Trying to do a search/replace over a file, for a given string, and > replacing the string with a chunk of text that has multiple lines. > > From the cmdline, using sed, no prob. however, implementing sed, runs > into issues, that result in a "termination error"

Re: [Tutor] why it is showing attribute error in line7

2016-10-29 Thread Alan Gauld via Tutor
Please always post the full error text in future. Meanwhile I'll guess: On 29/10/16 05:42, SONU KUMAR wrote: > fname = raw_input("Enter file name: ") > if len(fname) < 1 : fname = "mbox-short.txt" > fh = open(fname) > count = 0 > for line in fh: >line=line.rstrip missing parens means you

Re: [Tutor] looking for image library based on PIL Image

2016-10-30 Thread Alan Gauld via Tutor
On 30/10/16 15:32, Benjamin Fishbein wrote: > I’m trying to automate a lot of images using PIL’s Image library, > but I don’t want to write all the filters and manipulation > algorithms myself. Do you know of any good code that people > have written that does this? It depends on what kind of

Re: [Tutor] Module webbrowser.os

2016-11-02 Thread Alan Gauld via Tutor
On 02/11/16 06:44, Palanikumar Gopalakrishnan wrote: > After that i want to experiment with webbrowser.os module, But dont know > how to execute it. webbrowser.os seems to just be a link to the standard os module. So you should read the docs for os...and use the os module directly. > So I use

Re: [Tutor] Cluster analysis script error

2016-10-11 Thread Alan Gauld via Tutor
On 11/10/16 22:13, Mike Armson wrote: > I am trying to run a script (attached) which determines the number of > clusters of fixations within a set of eye movement data. The script says to > enter the following command on python: > > "python fixationClusters.py outputPrefix input clusterDistance"

Re: [Tutor] Python Code Not Working

2016-10-11 Thread Alan Gauld via Tutor
On 09/10/16 21:39, jeremygaine...@gmail.com wrote: > Everytime I run this it says test is not defined . I don’t understand. It means test is not defined - that is, Python doesn't know about it. You call a function test() but there is no such function built into Python, so it complains.

Re: [Tutor] Python dependencies in Anaconda

2016-10-11 Thread Alan Gauld via Tutor
On 10/10/16 16:54, David Wolfe wrote: > Anaconda (using Spyder or a Juypter notebook), so the dependencies are > included, so it's not an issue. So, what I'm wondering is, are the > dependencies that are included in Anaconda just contained in Anaconda, and > not actually accessible in Python,

Re: [Tutor] Adding numbers within a string

2016-10-12 Thread Alan Gauld via Tutor
On 12/10/16 01:37, LQ Soh wrote: > To whom it may concern, > Can someone enlighten me as to how you can create a function such > that sum_numbers('10 5 8'), when run, will give an answer of 23, without > using str.split() and using a for loop I'm assuming this is some kind of classroom exercise?

Re: [Tutor] Need help

2016-10-12 Thread Alan Gauld via Tutor
On 12/10/16 09:03, niraj pandey wrote: > Can you pls guide how to print this screen (Attached here) content in > printer ? As we already pointed out this is a text list so attachments are usually stripped off... However, printing from Tkinter is not easy. The simplest way is usually to create

Re: [Tutor] Advise with coding

2016-10-11 Thread Alan Gauld via Tutor
On 11/10/16 10:16, tracey jones-Francis wrote: > Is it possible someone on here can advise me where I am going wrong. Yesm, thats what this list is for but... We need to see code - we can't guess what you did. We need to know what input you used, what output you got and why its not what you

Re: [Tutor] Python help

2016-10-16 Thread Alan Gauld via Tutor
On 15/10/16 23:48, Nicholas Hopkins wrote: > Please tell me what is wrong with my code and how I can put an if else > statement > inside of another if else statement You are almost right but... > This is my code: > path = input('Which path number will you take?') > if path == '1': >

Re: [Tutor] Adding numbers within a string

2016-10-12 Thread Alan Gauld via Tutor
On 12/10/16 17:58, D.V.N.Sarma డి.వి.ఎన్.శర్మ wrote: > Sorry, I did not read the conditions that split and for should not be used. It is even more confusing - split() may NOT be used but 'for' MUST be used... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/

Re: [Tutor] Help on Software Design decisions

2016-11-29 Thread Alan Gauld via Tutor
On 29/11/16 02:02, Juan C. wrote: >>> I have to build my own Moodle API to be consumed by my program, I just noticed the last bit. Is this a client side API or a server side API? In other words are you building a set of services on the server or are you building a module that makes it easy for

Re: [Tutor] function argument unpacking

2016-12-08 Thread Alan Gauld via Tutor
On 08/12/16 06:04, Palanikumar wrote: > #Function Argument unpacking > def myfunc(x, y, z): > print(x. v. z) > Please always send the actual code that generates the error, do not retype as it causes us to chase phantom bugs. In this case the fact that the v in the print statement should be

Re: [Tutor] problem with scroll in Tkinter

2017-01-13 Thread Alan Gauld via Tutor
On 13/01/17 06:55, Ali Moradi wrote: > https://paste.pound-python.org/show/CIKA8eOFbdq18r3nFUBv/ > > On Fri, Jan 13, 2017 at 10:25 AM, Ali Moradi wrote: > >> hi. I've written this code and i can't fix the scrollbar error. i am a >> beginner in Python plz help. this is

Re: [Tutor] small remark

2017-01-11 Thread Alan Gauld via Tutor
On 10/01/17 17:56, adil gourinda wrote: >When I was surfing in “Python Library” I made some observations and I want > to share them That's good and as a place to discuss those observations the tutor list is a suitable forum. However, if you want the proposals considered for actual

Re: [Tutor] Importing classes

2017-01-11 Thread Alan Gauld via Tutor
On 11/01/17 02:53, kay Cee wrote: > Is there a proper way to import a class from a module? If so, please tell. The most common way is probably: >>> from mymodule import Myclass >>> myobject = Myclass() but its just as good to do >>> import mymodule >>> myobject = mymodule.Myclass() --

Re: [Tutor] Convert tuple within tuple into single tuple

2017-01-11 Thread Alan Gauld via Tutor
On 11/01/17 06:31, ramakrishna reddy wrote: > Hi All, > > Is there any way to convert x = (1, 2, 3, (4, 5)) to x = (1, 2, 3, 4, 5) in > python 2.7 You can write a function(*) to flatten the data structure, but you need to be careful and think through how you expect it to handle strings, say...

Re: [Tutor] Ran into a problem: Tried many different methods

2016-11-30 Thread Alan Gauld via Tutor
On 30/11/16 02:29, Parish Watteau wrote: > A program that will read each player’s name and golf score as > keyboard input, and then save these as records in a file named golf.txt. > (Each record will have a field for the player’s name and a field for the > player’s score.) > > I attempted

Re: [Tutor] copy files selectively from source to destination

2016-12-05 Thread Alan Gauld via Tutor
On 05/12/16 16:20, anatta anatta wrote: > I however want to copy selective files. > For example I like to copy only .txt files only > How could I do this selective copying? By applying an if test just before you copy filetype = '.txt' # or read it as an input ... if sourcefile extension

Re: [Tutor] Total newbie question

2017-01-04 Thread Alan Gauld via Tutor
On 04/01/17 06:51, MR ZenWiz wrote: > It appears that while python is installed in /usr/bin, idle is in > /usr/local/bin and expects the python interpreter to be also under > /usr/local, which does not seem to be the default. > > I created a symlink 'ln -s /usr/bin/python3.5 >

Re: [Tutor] Challenges with psycopg2 on Python 3.2

2017-01-06 Thread Alan Gauld via Tutor
On 06/01/17 12:55, Admire Mutsikiwa wrote: > it screams on the Python3.2 prompt, it gives Hardly screaming, rather a polite complaint that you've messed up your indentation. import psycopg2 > File "", line 1 > import psycopg2 > ^ > IndentationError: unexpected indent I'll guess

Re: [Tutor] Total newbie question

2017-01-03 Thread Alan Gauld via Tutor
On 03/01/17 01:21, MR ZenWiz wrote: > I'm trying to install python 4.6 on my Xubuntu 16.04 desktop, I assume you mean Python 3.6? And my first question is why? Do you have some specific features in 3.6 that you need? Otherwise just go with the latest version in your package manager which will

Re: [Tutor] prenting a line form appearing in log file

2017-01-05 Thread Alan Gauld via Tutor
On 05/01/17 13:01, anatta anatta wrote: > I have created a log file, using 'logging' module, > name = raw_input ("Please enter your name.") > print 'Hi ', name, 'Please go ahead and press enter to transfer files' > > The log file records the variable 'name' in the log file at the > right

Re: [Tutor] help :making window

2016-12-31 Thread Alan Gauld via Tutor
On 31/12/16 16:05, syafiqah amir via Tutor wrote: > Hello,Im trying to execute the code but the window does not come out. Please always post python code in plain text, otherwise the html gets wrapped and it becomes illegible. > (script from Maya python for games and film) This group is for

Re: [Tutor] path string

2017-01-02 Thread Alan Gauld via Tutor
On 02/01/17 17:01, anatta anatta wrote: > I am trying to create unsuccessfully source path as > a string 'str7' in part_1 of the code below, When you say unsuccessfully what do you mean? What do you expect? What do you get? > to be used in part_2 of the code. For that you need to expose it

Re: [Tutor] Fw: path string

2017-01-04 Thread Alan Gauld via Tutor
On 03/01/17 15:59, anatta anatta wrote: > Please disregard my request below. > > I know the problem! > > I have not defined the variable in question as a global variable. That's one solution but its not a very good one. Global variables are not considered good practice for many reasons. In

Re: [Tutor] Help with a Conversion

2017-01-05 Thread Alan Gauld via Tutor
On 05/01/17 13:29, S. P. Molnar wrote: > Fortran II using punched paper tape. Yes, am a rather elderly . . .). You are not the only one, there are at least 2 more of us on this list that started in that era... > short program to change frequency to wavelength for a plot of > ultraviolet

Re: [Tutor] I download package and it says computer is missing this file, how do I fix?

2016-12-23 Thread Alan Gauld via Tutor
On 23/12/16 01:47, Don Pryor wrote: > [image: Inline image 1] > This is a text mailing list so the server strips out most attachments. You need to tell us a lot more. 1) What package are you trying to install 2) How are you downloading/installing it(pip/ftp/binary installer?) 3) Which OS and

Re: [Tutor] How to interact with the result of subprocess.call()

2016-12-24 Thread Alan Gauld via Tutor
On 25/12/16 01:21, Jim Byrnes wrote: > I am not trying to automate libreoffice using subprocess. No, but you are trying to automate LO from within Python by sending it keystrokes and that's not easy. That's why I previously asked whether you really wanted to open the LO file directly and

Re: [Tutor] formatting xml (again)

2016-12-27 Thread Alan Gauld via Tutor
On 27/12/16 19:44, richard kappler wrote: > Using python 2.7 - I have a large log file we recorded of streamed xml data > that I now need to feed into another app for stress testing. The problem is > the data comes in 2 formats. > > 1. each 'event' is a full set of xml data with opening and

Re: [Tutor] How to interact with the result of subprocess.call()

2016-12-25 Thread Alan Gauld via Tutor
On 25/12/16 01:58, boB Stepp wrote: > the stdin option of call()might be used to direct the desired > keystrokes to LO? After looking at The problem is that keystrokes in a GUI are not read from stdin, they are read as events from the GUI event loop. So, if LO was a CLI tool (like vim or top,

Re: [Tutor] How to interact with the result of subprocess.call()

2016-12-25 Thread Alan Gauld via Tutor
On 25/12/16 17:08, boB Stepp wrote: > Then I see that I have a GCE (Gross Conceptual Error) floating around. > I thought that event loops are just intercepting the redirected stdin > from the keyboard. This is not true? If not, then how is this > working? No event loops don't use stdin. They

Re: [Tutor] IndexError: list index out of range

2016-12-27 Thread Alan Gauld via Tutor
On 27/12/16 15:22, Mysore Ventaka Rama Kumar wrote: > Please review and comment/correct my error! Rather than expect us to read through many lines of code it would help id you posted the entire error message which will tell us exactly where the problem lies. Also tell us for completeness which

Re: [Tutor] Fwd: Question about selenium with python

2016-12-22 Thread Alan Gauld via Tutor
On 21/12/16 01:29, Fazal Khan wrote: > Im a new programmer and this is my first time posting here. I have a > question about using selenium with python. I notice you haven't had an answer yet. That may be because Selenium is not part of the standard Python library and this list is for questions

Re: [Tutor] Trouble Launching Python

2016-12-22 Thread Alan Gauld via Tutor
On 19/12/16 22:38, Joseph Olugbohunmi via Tutor wrote: > Hello,Good day, I installed Python 3.5.2 on my Windows 8.1 PC Are you sure you used the right Python version. There are separate downloads for 32 and 64 bit machines. It may be that you downloaded the 64 bit version and have a 32bit OS

Re: [Tutor] Using Python to solve factoria

2016-12-22 Thread Alan Gauld via Tutor
On 21/12/16 07:50, Hedgar wrote: > I really happy to be accepted to the list! You're welcome, but one very important thing to note is that you should always post to this list in plain text, not HTML. That's because HTML loses the formatting of the code (see below) and in Python formatting is

Re: [Tutor] Open a libreoffice calc file in Python

2016-12-22 Thread Alan Gauld via Tutor
On 22/12/16 03:37, Jim Byrnes wrote: > Python 3.4 on Ubuntu > > If I was going to open a libreoffice calc file from the terminal I would > go: libreoffice --calc /home/path/to/myfile.ods. > > How would I do this from Python? Others have advised how to run the Libreoffice app from within

Re: [Tutor] accessing attribute from python programming for absolute beginner

2016-12-26 Thread Alan Gauld via Tutor
On 26/12/16 04:08, syafiqah amir via Tutor wrote: > i did not achieve the desired outcome which is the name of the critters did > not print > #attribute Critter#Demonstrates creating and accessing object attributes > class Critter(object):"""A virtual pet"""def __init__(self,name):

Re: [Tutor] Manipulating Dictionary values

2016-12-26 Thread Alan Gauld via Tutor
On 26/12/16 08:03, Sunil Tech wrote: > Hi Team, > > Dictionary is like > > a = {'a': 'New', 'b': 'Two', 'l': [{'k': 'test', 'm': 'again'}, {'k': > 'test', 'm': 'again'}]} > > I am trying to modify a value in the dictionary value at a['l'] So make life easy for yourself and get rid of the outer

Re: [Tutor] How to interact with the result of subprocess.call()

2016-12-26 Thread Alan Gauld via Tutor
On 25/12/16 16:33, Jim Byrnes wrote: >> (*)LO remembers its last screen setting and opens with them, >> if those screen settings are different than the ones you >> programmed for then navigation will be different and so on. > > I don't think I need to "know where stuff is" to manipulate LO. It

Re: [Tutor] Using Class Properly - early beginner question

2017-03-23 Thread Alan Gauld via Tutor
On 22/03/17 12:30, Rafael Knuth wrote: > I wrote a function that does exactly what I want, and that is: > Create a shopping list and then let the user decide which items (food) > are supposed to be instantly consumed and which ones stored. That's a good start, because it means you understand

Re: [Tutor] Scrollbar

2017-03-27 Thread Alan Gauld via Tutor
On 27/03/17 17:22, Pooja Bhalode wrote: > The scrollbar goes not work in the window. Define 'not work'? You haven't connected it to anything and it doesn't respond to any events so what kind of work did you expect it to do? I assume it draws itself on screen and the scroll buttons operate OK

Re: [Tutor] Using Class Properly - early beginner question

2017-03-24 Thread Alan Gauld via Tutor
On 24/03/17 21:41, boB Stepp wrote: >> I have a question: When creating an instance of GroceryListMaker, you are >> using: >> >> if __name__ == "__main__": >> >> What is that specifically for? Its a common trick in Python that enables a single file to act as both a module and a program. When a

Re: [Tutor] Using Class Properly - early beginner question

2017-03-24 Thread Alan Gauld via Tutor
On 24/03/17 21:42, boB Stepp wrote: >> I noticed that you split your class into three methods: Many real world classes have a lot more than 3 methods. >> def __init__(self): >> # initialize instances of class >> >> def make_shopping_list(self): >> # input >> >> def display_shopping_list(self):

Re: [Tutor] Retrieving DropDown List Values

2017-03-25 Thread Alan Gauld via Tutor
On 25/03/17 04:29, Braxton Jackson wrote: > Is there a simple command for retrieving the chosen value a user inputs > from a dropdown list? I am new to Python and cant seem to find a good > tutorials link on retreiving drop down values. That all depends on which GUI toolkit you are using. The

Re: [Tutor] Function question

2017-03-25 Thread Alan Gauld via Tutor
On 25/03/17 10:01, Peter O'Doherty wrote: > def myFunc(num): > for i in range(num): > print(i) > > print(myFunc(4)) > 0 > 1 > 2 > 3 > None #why None here? Because your function does not have an explicit return value so Python returns its default value - None. So the print() inside

Re: [Tutor] super constructor usage

2017-03-30 Thread Alan Gauld via Tutor
On 30/03/17 12:39, Rafael Knuth wrote: I am trying to wrap my head around the super constructor. > > Is it possible to embed a super constructor into an if / elif > statement within the child class? Of course, the __init__ methods are special in any way the normal coding mechanisms all

Re: [Tutor] Help with function scoping

2017-03-23 Thread Alan Gauld via Tutor
On 23/03/17 10:15, Richard Mcewan wrote: > #loop to check guess and report > while userGuess != computerGuess: > if userGuess < computerGuess: > print('Too low') > userGuess = getUser() > elif userGuess > computerGuess: > print('Too high') >

Re: [Tutor] Help with function scoping

2017-03-22 Thread Alan Gauld via Tutor
On 22/03/17 21:17, Richard Mcewan wrote: > I'm expecting two functions to be defined. Then called. And thats what you've got. But... > One returns a random number. The other user input (guessing the number). And thats also what you've got but you don't do anything with the returned value you

Re: [Tutor] super constructor usage

2017-03-29 Thread Alan Gauld via Tutor
On 29/03/17 15:33, Rafael Knuth wrote: > I am trying to wrap my head around the super constructor. This is one of these cases where it matters whether you are using Python v2 or v3. Use of super in v3 is much easier. It looks from your examples like you are using v2 but it would be good to

Re: [Tutor] FUNCTIONS vs. CLASSES (early beginner questions)

2017-03-28 Thread Alan Gauld via Tutor
On 28/03/17 17:45, Rafael Knuth wrote: > Question: When should I use functions? > When should I use classes? Thee is no definitive answer but here are some guidelines: 1) Many instances -> class 2) Many methods sharing the same data -> class 3) An algorithm that has no side effects -> a function

Re: [Tutor] Merge Sort Algorithm

2017-03-28 Thread Alan Gauld via Tutor
On 28/03/17 15:56, Elo Okonkwo wrote: > Can someone pls explain this Merge Sort Algorithm, You can try reading this generic explanation. It's not Python but the explanation seems fairly clear. http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/Sorting/mergeSort.htm HTH -- Alan G

Re: [Tutor] super constructor usage

2017-03-31 Thread Alan Gauld via Tutor
On 30/03/17 21:08, Alan Gauld via Tutor wrote: > Of course, the __init__ methods are special in any way Should have said *not special* in any way... > But remember that not calling super potentially leaves > some attributes of your superclass uninitialized. By not > calling supe

Re: [Tutor] python gtk serial loop thread readind data close

2017-03-31 Thread Alan Gauld via Tutor
On 30/03/17 13:40, Alexandru Achim via Tutor wrote: > Dear users, > I had a problem regarding Threads in python and Gtk3. This list is really for the core language and library, I suspect you might get a better response by asking on the PyGTK forum where there are more likely to be people who have

Re: [Tutor] All Entry Boxes taking the same value

2017-03-31 Thread Alan Gauld via Tutor
On 30/03/17 21:35, Pooja Bhalode wrote: > *However, when I execute it, and type something in one entrybox, it shows > in all the entry boxes using multi-cursor option. * I'm not sure whats going on and don;t habe tome to experiment but one thing I noticed: > average = [" ", " ", " "] > lowest =

Re: [Tutor] tiny, little issue with list

2017-03-19 Thread Alan Gauld via Tutor
On 19/03/17 12:17, Rafael Knuth wrote: > LogActivities = [] > prompt = ("What have you done today? ") > prompt += ("Enter 'quit' to exit. ") I'm not sure why you put that on two lines but thats just a nit pick... > while True: This will loop forever unless you explicitly break, return or hit an

Re: [Tutor] cx_Oracle and Pyinstaller

2017-03-14 Thread Alan Gauld via Tutor
On 14/03/17 14:29, Madhu Venkat wrote: > try: > Conn = cx_Oracle.connect (self.dsn) > except cx_Oracle.DatabaseError as exception: > > dsn has all the required connection info. > > In this case, I believe I don't need TNSnames.ora file, please confirm. I don't know

Re: [Tutor] Summing arrays

2017-03-16 Thread Alan Gauld via Tutor
On 16/03/17 05:11, Aaliyah Ebrahim wrote: > def sum2(N): > > b = np.arange(1,N+1,1) > mylist = [ ] > for i in b: > terms = 2*(1+3**(i-1)) > a = mylist.append[terms] > return np.sum(mylist) > terms = 2*(1+3**(i-1))> 9 mylist.append[terms] 10 >

Re: [Tutor] While condition

2017-03-17 Thread Alan Gauld via Tutor
On 17/03/17 14:46, Aaliyah Ebrahim wrote: > Hi, in my code below, why is it returning a value that is greater than 1200 > if my condition is that the value should be less than 1200? Your condition is that it be less than 1200 when it enters the loop body. That means it will *always* be 1200 or

Re: [Tutor] CSV file Reading in python

2017-03-22 Thread Alan Gauld via Tutor
On 20/03/17 19:37, Edzard de Vries wrote: > I have a CSV which I want to be able to read in Python. Are you using the csv module? Have you read the documentation for that? It gives several examples. If not already then use csv. If you are using it and still have problems send the code and

Re: [Tutor] HTML module for Python

2017-03-22 Thread Alan Gauld via Tutor
On 20/03/17 22:09, ਪੰਜਾਬ ਪੰਜਾਬੀ wrote: > Looking for recommendations on Python module to use to generate HTML > pages/tables, other HTML content. Kindly help. While thee are some modules that help with this most Python programs I've seen just generate the HTML directly as strings. There is no

Re: [Tutor] How do we create a GUI to run a simple calculation program in Python?

2017-04-04 Thread Alan Gauld via Tutor
On 04/04/17 17:55, Lisa Hasler Waters wrote: > A middle school student of mine created a program to calculate simple and > compound interest. He built it in PyCharm EDU using a Mac running 10.11.6. > > He would like to create a GUI to run this program. Please, can you advise > on how he could

Re: [Tutor] Validating String contains IP address

2017-04-03 Thread Alan Gauld via Tutor
On 03/04/17 19:43, Ed Manning wrote: > untrust_ip_address = raw_input('\nEnter the untrust IP ''"Example > 172.20.2.3/28"'':') > while not ipaddress.ip_network untrust_ip_address: Doesn't that give a syntax error? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/

Re: [Tutor] Count for loops

2017-04-03 Thread Alan Gauld via Tutor
On 04/04/17 00:37, D.V.N.Sarma డి.వి.ఎన్.శర్మ wrote: > I will go for this modification of the original code. > count = 0 > b= '3'+b[2:] > n = len(b) > for i in range(n-4): > if b[i:i+4] == get_year: > count += 1 While I think this works OK, I would probably suggest that this is one

Re: [Tutor] Count for loops

2017-04-04 Thread Alan Gauld via Tutor
On 04/04/17 12:04, Rafael Knuth wrote: > Sarma: thank you so much, I checked your code, it works. However, can > you enlighten me what it exactly does? It just iterates over the PI string manually and compares the birth date with the first 4 PI string characters. It would probably be more

Re: [Tutor] learning resources

2017-04-04 Thread Alan Gauld via Tutor
On 04/04/17 12:19, brian mituka wrote: > what are the best learning resources for a beginner in python... Look on Python.org and you will find a beginners page with many links. But... it will depend on whether you can already program in another language which beginners page you go to. I am, of

Re: [Tutor] What would be good use cases for the enum module?

2017-04-09 Thread Alan Gauld via Tutor
On 09/04/17 13:58, Mats Wichmann wrote: > All of these can of course be done without enums. So the extra benefit > of an enum is that the set is closed (immutable) and requires > uniqueness: picking some other value will be an error, Indeed, good catch. The value of an enum over an integer is

Re: [Tutor] Tkinter entry box text changed event

2017-04-10 Thread Alan Gauld via Tutor
On 10/04/17 10:18, Phil wrote: > def my_method(self.event): > print("method called") > > (self.event) is a syntax error and if I leave off "self", this is the result: You want two parameters self becaiuse its a method of a class so must have a self event which is the event passsed by the

Re: [Tutor] Count for loops

2017-04-11 Thread Alan Gauld via Tutor
On 11/04/17 17:48, Rafael Knuth wrote: > Pi_Number = str(3.14159265358979323846264338327950288419716939) > Pi_Number = "3" + Pi_Number[2:] > print(Pi_Number) > 3141592653589793 > > How come that not the entire string is being printed, but only the > first 16 digits? There are two problems

Re: [Tutor] Count for loops

2017-04-11 Thread Alan Gauld via Tutor
On 11/04/17 19:44, Mats Wichmann wrote: > import decimal > > Pi_Number = > str(decimal.Decimal(3.14159265358979323846264338327950288419716939)) > Unfortunately that doesn't work either: >>> " " + str(decimal.Decimal( ... 3.14159265358979323846264338327950288419716939)) '

Re: [Tutor] Count for loops

2017-04-03 Thread Alan Gauld via Tutor
On 03/04/17 13:22, Rafael Knuth wrote: > with open (file_path) as a: > b = a.read() > > get_year = input("What year were you born? ") > > for year in b: Can you explain what you think this loop line is doing? I'm pretty sure it's not doing what you expect. > if get_year in b: >

Re: [Tutor] Count for loops

2017-04-03 Thread Alan Gauld via Tutor
On 03/04/17 16:42, D.V.N.Sarma డి.వి.ఎన్.శర్మ wrote: > Sorry. That was stupid of me. The loop does nothing. Let me rewrite the code with some different variable names... >>> with open(file_path) as a: >>> b = a.read() with open (file_path) as PI_text: PI_as_a_long_string =

Re: [Tutor] Count for loops

2017-04-03 Thread Alan Gauld via Tutor
On 03/04/17 16:42, D.V.N.Sarma డి.వి.ఎన్.శర్మ wrote: > Sorry. That was stupid of me. The loop does nothing. > On the contrary, the loop does an awful lot, just not what the OP was expecting. >>> with open(file_path) as a: >>> b = a.read() >>> for year in b: >>> if get_year in b: >>>

Re: [Tutor] Count for loops

2017-04-03 Thread Alan Gauld via Tutor
On 03/04/17 16:07, D.V.N.Sarma డి.వి.ఎన్.శర్మ wrote: > Modifying the code as shown below may work. I doubt it. > with open(file_path) as a: > b = a.read() > > get_year = input("What year were you born? ") > > count = 0 > for year in b: Once more I ask, what does this loop do? > if

Re: [Tutor] Asking about Run python script at Startup

2017-04-03 Thread Alan Gauld via Tutor
On 03/04/17 05:34, Quang nguyen wrote: > I do not know how to run my python 3 script after my PI2 finished startup. This might be a better question for a PI forum since it doesn't seem to have anything directly to do with Python. > the easy way to run at startup with escape plan?. You will

Re: [Tutor] Validating String contains IP address

2017-03-31 Thread Alan Gauld via Tutor
On 01/04/17 00:35, Ed Manning wrote: > > What's the best way to validate a string contains a IP address It depends on how thorough you want to be. You can define a regex to check that its 4 groups of numbers separated by periods. Or you can split the string into fields and validate that the

Re: [Tutor] Euclidean Distances between Atoms in a Molecule.

2017-04-02 Thread Alan Gauld via Tutor
On 02/04/17 18:41, Stephen P. Molnar wrote: > I am trying to port a program that I wrote in FORTRAN twenty years ago > into Python 3 and am having a hard time trying to calculate the > Euclidean distance between each atom in the molecule and every other > atom in the molecule. Sounds highly

Re: [Tutor] Startup Python

2017-04-12 Thread Alan Gauld via Tutor
On 12/04/17 13:47, Wim Berrelkamp wrote: a=2 Here you assign the number 2 to 'a' d=a+4 print(d) > 6 > a=input('-->' ) Here you assign whatever character(s) the user types to 'a'. The fact that it looks like 2 doesn't change the fact that it is really the character '2'. So you

Re: [Tutor] Question to Phyton and XBee

2017-04-12 Thread Alan Gauld via Tutor
On 12/04/17 15:32, Daniel Berger wrote: >For me it is not clear what is going wrong and I would be happy to get >some help to solve the problem. This list is for the core language and library, so while we can help with installing third party packages that doesn't mean anyone here will

Re: [Tutor] Network Sniffing on Windows with Python 3.6

2017-04-07 Thread Alan Gauld via Tutor
On 07/04/17 06:07, Some Developer wrote: > How would I go about writing a Python 3.6 script for Windows that would > sniff the network traffic and take the individual packets and then > reassemble them into something that is useful data? That is definitely possible using Python although it is

Re: [Tutor] Tkinter grid question

2017-04-07 Thread Alan Gauld via Tutor
On 07/04/17 11:08, Phil wrote: > ...In this case I become confused because had expected [][] > to be the same as a C two dimensional array. It is, sort of. If you set the data up correctly to start with :-) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/

Re: [Tutor] [Python 3.5] TypeError: a bytes-like object is required, not 'str' PICKLE

2017-04-07 Thread Alan Gauld via Tutor
Please always send the full error trace not just the last line. The message is full of useful details which we can't currently see. On 07/04/17 09:28, Allan Tanaka via Tutor wrote: > Hi > I have added b so that it translates into bytes object. save_cPickle part is > not problem... > But i

Re: [Tutor] Tkinter grid question

2017-04-07 Thread Alan Gauld via Tutor
On 07/04/17 03:09, Phil wrote: > Thank you for reading this. > > This is my first attempt at using Tkinter and I've quickly run into a problem. > Peter has already answered the problem but I'd like to point out how he used the interactive prompt >>> to demonstrate what was going wrong. You

Re: [Tutor] Question about loop and assigning variables

2017-04-05 Thread Alan Gauld via Tutor
On 05/04/17 20:07, Fazal Khan wrote: > assign different variables with each loop You can't, but you can fake it... > def BeamInfo(x): > for Bnum in x: > if plan1.IonBeamSequence[Bnum].ScanMode == 'MODULATED': > TxTableAngle = >

Re: [Tutor] (no subject)

2017-04-09 Thread Alan Gauld via Tutor
On 09/04/17 11:42, shubham goyal wrote: > Hello, I am a c++ programmer and wants to learn python for internship > purposes. How can i learn the advanced python fast mostly data science > packages, I know basic python. There are tutorials on most things. But it depends on what you mean by advanced

Re: [Tutor] counting function calls

2017-04-10 Thread Alan Gauld via Tutor
On 10/04/17 08:55, marcus lütolf wrote: > Dear experts, > I have written the following code for motion detection with a PIR sensor > with a function and > I need to count how many times the funtion is called, but I get a traceback: > > #!/usr/bin/python3 > import sys, time > import RPi.GPIO as

Re: [Tutor] Count for loops

2017-04-08 Thread Alan Gauld via Tutor
On 08/04/17 13:49, Rafael Knuth wrote: >> b = "3"+b[2:] #Removing the decimal point so that there are digits only in > > my_number = 3.14159 Here you assign a floating point number to mmy_number but the code Sama wrote was for working with strings read from a text file. You would need to

Re: [Tutor] Tkinter entry box text changed event

2017-04-10 Thread Alan Gauld via Tutor
On 10/04/17 05:43, Phil wrote: > I would like a function to be called when I enter text > and then tab to the next entry box. One of the things about Entry boxes is that they are extremely flexible and have many event types associated with them. The consequence of this is that you as a

Re: [Tutor] What would be good use cases for the enum module?

2017-04-09 Thread Alan Gauld via Tutor
On 09/04/17 04:00, boB Stepp wrote: > understandable to me, but I am having difficulty imagining where I > might want to use these features. > Steven has given the basics, here are a few more real world examples: Any kind of status value: (open,closed,opening, closing,locked) - control valve

Re: [Tutor] sorted function

2017-04-14 Thread Alan Gauld via Tutor
On 14/04/17 19:29, shubham goyal wrote: > sorted function is not working when i am trying to sort the list of strings > but list.sort() is working. can you please help me understand. sort() sorts the list "in place". That is it sorts itself. sorted() returns a sorted copy of the list. It does

Re: [Tutor] creating .json files

2017-04-13 Thread Alan Gauld via Tutor
On 13/04/17 17:32, Rafael Knuth wrote: > Is there a way to split these two into separate steps: > a) creating a .json file > b) manipulating it (a, r, w ...) Of course. > What if I just wanted to create a .json file and do nothing with it? > > import json > file_name = "my_numbers.json" > >

Re: [Tutor] Need help with code

2017-04-17 Thread Alan Gauld via Tutor
On 16/04/17 18:26, Tyler Seacrist wrote: > I need to draw a stack diagram for print_n > called with s = 'Hello' and n=2 and am unsure of how to do so. Me too. What is print_n? Which stack? One in your program or the interpreters internal stack? We need a lot more detail. -- Alan G Author

Re: [Tutor] Using Modules

2017-04-15 Thread Alan Gauld via Tutor
On 15/04/17 09:33, Aero Maxx D wrote: > With Python I'm not finding which modules I need Search for the functionality within the python.org site. The documentation tells you which module you are looking for. > ...I thought I'd connect to a MySQL database There is a standard DB interface in

Re: [Tutor] How do we create a GUI to run a simple calculation program in Python?

2017-04-15 Thread Alan Gauld via Tutor
On 15/04/17 03:38, Alex Kleider wrote: >> Whatever he does he will need to separate his UI from his >> logic - a good programming skill regardless of UI. > > Can anyone suggest a good tutorial that explains exactly what this means > and how to achieve it? > (separate UI from logic I mean.) I

Re: [Tutor] Do not understand code snippet from "26.8. test — Regression tests package for Python"

2017-04-17 Thread Alan Gauld via Tutor
On 17/04/17 05:01, boB Stepp wrote: > Am I missing anything? If not, then why did the code snippet use the > (I believe to be misleading.) class variable approach with "func = > mySuperWhammyFunction" and "self.func(self.arg)"? I suspect it was a slightly broken attempt at reuse in that you can

Re: [Tutor] Tkinter layout question

2017-04-20 Thread Alan Gauld via Tutor
On 20/04/17 10:33, Phil wrote: >> So, for a Suduko grid put 3x3 Entry boxes into a Frame. >> Then put 3x3 such frames into another frame. > > OK, so I'll go back to my original idea and use edit boxes. A grid of 9 x 9 > edit boxes does actually work and it makes it easy to keep track of the >

<    1   2   3   4   5   6   7   8   9   10   >