Re: [Tutor] Chunking list/array data?

2019-08-22 Thread Peter Otten
Sarah Hembree wrote: > How do you chunk data? We came up with the below snippet. It works (with > integer list data) for our needs, but it seems so clunky. > > def _chunks(lst: list, size: int) -> list: > return [lst[x:x+size] for x in range(0, len(lst), size)] > > What do you do?

Re: [Tutor] which of these is more efficient?

2019-08-19 Thread Peter Otten
nathan tech wrote: > Hi there, > > So I am running over some coding ideas in my head for creating a map for > a game. > > This map would expand based on how far the user explores. > > I figure there are two ways to do this: > > 1: the list method: > > map=[] > > for x in range(3): > >

Re: [Tutor] What is Tuple in the typing module?

2019-08-17 Thread Peter Otten
C W wrote: > Hi everyone, > > What exactly is Tuple in the typing module? What does it do? > > This is the definition from its website. > https://docs.python.org/3/library/typing.html > "A type alias is defined by assigning the type to the alias" > > I have no idea what that means. > > Here's

Re: [Tutor] Search for Text in File

2019-08-15 Thread Peter Otten
Stephen P. Molnar wrote: > I need to find a phrase in i text file in order to read a unique text > string into a python3 application. > > I have become stuck and Google has not been of any use. > > Here is my attempt: > import re > > name = input("Enter Molecule Name: ") > > name_in =

Re: [Tutor] cgi module help

2019-08-13 Thread Peter Otten
rmli...@riseup.net wrote: > I have a question about the cgi module. > > I'm trying to retrieve post data as a nested dictionary from client > code. > > For instance: > > > > """client code""" > from requests import sessions > from datetime import datetime > > session = sessions.Session() >

Re: [Tutor] class functions/staticmethod?

2019-08-12 Thread Peter Otten
James Hartley wrote: > I am lacking in understanding of the @staticmethod property. > Explanation(s)/links might be helpful. I have not found the descriptions > found in the Internet wild to be particularly instructive. Given the code > below: > =8<-- > from collections

Re: [Tutor] Object creation query

2019-08-09 Thread Peter Otten
mhysnm1...@gmail.com wrote: > All, > > > > I think I am asking for the impossible here. But I will ask anyway. > > > > I am using flask_sqlalchemy to build the tables and perform the queries, > updates and insertions. I have multiple tables with the same structure > with

Re: [Tutor] Create Logging module

2019-08-01 Thread Peter Otten
Sinardy Xing wrote: > following is my main app > > -- start here-- > from loggingme import logme > > def say_hello(name, age): > print('Hello {}, I am {}'.format(name, age)) > > #say_hello=logme(say_hello('Sinardy')) > @logme > say_hello('Tonny', 8) Isn't this a SyntaxError? You can

Re: [Tutor] Reading .csv data vs. reading an array

2019-07-16 Thread Peter Otten
Chip Wachob wrote: > I tried it anyhow, with this being an example of my source data: > > "Record Length",202,"Points",-0.005640001706,1.6363 > "Sample Interval",5e-09,s,-0.005639996706,1.65291 > "Trigger Point",1128000,"Samples",-0.005639991706,1.65291 > "Trigger

Re: [Tutor] replacing a loop

2019-06-24 Thread Peter Otten
johnf wrote: > Hi folks, > > > I have the following loop (actually repeated many times ) If you have repetetive code look into ways to parameterize it, like def choices(rows, choices_column, keys_column): ... > > def locChoices(self): > locDS = self.eslocation.getDataSet() >

Re: [Tutor] os.is_file and os.is_dir missing from CPython 3.8.0b?

2019-06-14 Thread Peter Otten
Tom Hale wrote: > I'm trying to use os.is_dir, but I'm not finding it or os.is_file. > > What am I missing here? Scroll up a bit in the documentation: https://docs.python.org/3.8/library/os.html#os.DirEntry Both is_file() and is_dir() are methods of the DirEntry object. See also

Re: [Tutor] Running Lib/test/test_shutil.py

2019-06-13 Thread Peter Otten
Tom Hale wrote: > Hi all, > > I hope this is the best place to ask (please let me know if there is a > more appropriate list): > > Checking out CPython v3.8.0b1, I'm trying to run: > >% python Lib/test/test_shutil.py Are you sure % python invokes the 3.8 interpreter? > I'm getting: >

Re: [Tutor] Error when trying to insert csv values into a sql table

2019-06-11 Thread Peter Otten
Cravan wrote: > Here is the stack overflow link: > https://stackoverflow.com/questions/56540292/error-when-trying-to-insert-csv-values-into-a-sql-table > > > > I'm getting a weird error code when I try to store values from a csv into > an sql table in a movie review assignment. Like they say

Re: [Tutor] Collating date data from a csv file

2019-05-09 Thread Peter Otten
Cameron Simpson wrote: > On 08May2019 21:04, Dave Hill wrote: >>I have a csv file which details the results of equipment tests, I >>carry out PAT testing as a volunteer at a heriatge railway in N. >>Wales. I want to extract how many items were tested on each test day. >>So far I have generated a

Re: [Tutor] Help request ERROR installing beautifulsoup

2019-04-29 Thread Peter Otten
Dr. Luca T wrote: > Hi, > i'm new in python, i tried to install beautifulsoup but i had back this > error: > > ERROR: Complete output from command python setup.py egg_info: > ERROR: Traceback (most recent call last): > File "", line 1, in > File >

Re: [Tutor] What does 'Bind Return Key' do?

2019-04-29 Thread Peter Otten
Matthew Polack wrote: > Hi, > > We're learning Python with PySimpleGUi and have used this example > program... > > https://github.com/PySimpleGUI/PySimpleGUI/blob/master/ProgrammingClassExamples/Win10%20versions/1d%20PSG%20(named%20input%20keys%20and%20catch%20errors).py > > > There is a

Re: [Tutor] help with colormode

2019-04-25 Thread Peter Otten
Mark Alderson wrote: > hi > > Ihave a very small program. I want to cycle colours. I cant set the > colormode from 1 to 255 > > tried screen.colormode(255) > > tells me screen is not defined. the program works without the colormode, > but i want to use it. > > I just change the a and b

Re: [Tutor] What protocol to follow when need to pick either one from __getattr__ and __getattribute__ ?

2019-04-23 Thread Peter Otten
Arup Rakshit wrote: > I read today 2 methods regarding the customizing the attribute > access:__getattr__ and __getattribute__ from > https://docs.python.org/3/reference/datamodel.html#special-method-names. > What I understood about them is that __getattr__ is called when the > requested

Re: [Tutor] Help

2019-04-17 Thread Peter Otten
fatima butt wrote: > hi Peter, > hope you are well.I am getting the following error when i am running the > pygame shell script.I am using Acer SWIFT computer.my python version is > 3.7.3 and pygame version is pygame 1.9.5 > > Traceback (most recent call last): > File

Re: [Tutor] Fwd: uploading images in pygame

2019-04-17 Thread Peter Otten
fatima butt wrote: > the python version is 3.7.3 > computer is acer SWIFT > The error I get is following: > Traceback (most recent call last): > File "C:\Users\ammah\OneDrive\Documents\project1\myCode.py.py > ", line 84, in > background = >

[Tutor] Interoperating with Excel, was Re: Questions

2019-04-07 Thread Peter Otten
Diana Katz wrote: > 1) Can you use python from excel? Or just export to excel? > 2) I am trying to see if there's a way using python to automate all of > this work that I need to do. I have to collect quarterly segment data for > hundreds of public companies and go back at least 12-16 quarters.

Re: [Tutor] Encrypting shipped sqlite db in app directory

2019-03-30 Thread Peter Otten
Ali M wrote: > I want to encrypt my sqlite databases which are shipped with the app in > it's directory, so that the user can't modify or use it elsewhere, and > they will only be accessible for the app to read from, how can i do that? Assuming you had an encrypted database, where would you put

Re: [Tutor] (no subject)

2019-03-23 Thread Peter Otten
Matthew Herzog wrote: > I have a Python3 script that reads the first eight characters of every > filename in a directory in order to determine whether the file was created > before or after 180 days ago based on each file's name. The file names all > begin with MMDD or

Re: [Tutor] removing xml elements with ElementTree

2019-03-20 Thread Peter Otten
street.swee...@mailworks.org wrote: > An opportunity to work in Python, and the necessity of working with some > XML too large to visualize, got me thinking about an answer Alan Gauld had > written to me a few years ago > (https://mail.python.org/pipermail/tutor/2015-June/105810.html). I have >

Re: [Tutor] Merge a dictionary into a string

2019-03-16 Thread Peter Otten
Valerio Pachera wrote: > Consider this: > > import collections > d = OrderedDict(a='hallo', b='world') > > I wish to get a single string like this: > > 'a "hallo" b "world"' > > Notice I wish the double quote to be part of the string. > In other words I want to wrap the value of a and b. > >

Re: [Tutor] (no subject)

2019-03-16 Thread Peter Otten
Glenn Dickerson wrote: > class Student(): > > def__init__(self, name, major, gpa, is_on_probation): > self.name = name > self.major = major > self.gpa = gpa > self.is_on_probation = is_on_probation > > > import Student > student1 = Student('Jim', 'Business',

Re: [Tutor] My problem in simple terms

2019-03-04 Thread Peter Otten
Edward Kanja wrote: > Hi there , > Earlier i had sent an email on how to use re.sub function to eliminate > square brackets. I have simplified the statements. Attached txt file named > unon.Txt has the data im extracting from. The file named code.txt has the > codes I'm using to extract the

Re: [Tutor] Variable change within library depending on user input.

2019-03-04 Thread Peter Otten
Harry Oneill wrote: > Hey there everybody hope your doing great. > > I was here a few months ago and got pointed in the right direction very > kindly by one of the tutors. Im a little stuck again now and have been > researching for a while and can't come up with a solution to my problem. > >

Re: [Tutor] Remove soft line break

2019-03-01 Thread Peter Otten
Valerio Pachera wrote: [Me:] >> def merge_lines(lines): >> lines = (line.rstrip("\n") for line in lines) >> accu = [next(lines)] >> for line in lines: >> if line.startswith(" "): >> accu.append(line[1:]) >> else: >> yield "".join(accu) + "\n"

Re: [Tutor] Only appending one object to list, when I am expecting more than 1

2019-02-26 Thread Peter Otten
AdamC wrote: > I'm creating lots of objects from json in a file. Part of reading the json > back means that it iterates over the file and loads a json object and then > creates the object from the dictionary. > > This is my file: > > {"name": "Dwarf Fortress", "platform": "steam", "dateAdded":

Re: [Tutor] import failure

2019-02-22 Thread Peter Otten
Alex Kleider wrote: > (p2) alex@one:$ ./tests/run_data_tests.py Here you let the script decide which interpreter to pick... > Traceback (most recent call last): > ImportError: No module named tlslite.utils ...and it looks like it's not the one you'd like to have: > (p2) alex@one:$ python >

Re: [Tutor] text processing lines variable content

2019-02-07 Thread Peter Otten
ingo janssen wrote: > > > On 07/02/2019 11:08, Peter Otten wrote: >> replace the sequence of tests with dictionary lookups > > updated the gist a few times, now I could pre calculate the slices to be > taken per line, but will there be much gain compared to the copp

Re: [Tutor] text processing lines variable content

2019-02-07 Thread Peter Otten
ingo janssen wrote: > > On 07/02/2019 09:29, Peter Otten wrote: >> Where will you get the order from? > > Peter, > > the order comes from the command line. Then my one-function-per-format approach won't work. > I intend to call the python > program with

Re: [Tutor] text processing lines variable content

2019-02-07 Thread Peter Otten
ingo janssen wrote: > depending on how the input file is created data packet a can be in an > other position for every line. > figured out how to do it though > > order=[a,b,e,d...] > for i in lines: >i=i.split(" ") > for j in order: >if j = a: > use function for processing data

Re: [Tutor] help

2019-02-05 Thread Peter Otten
Sonia Miglani wrote: > Hi Team, > > I am learning puthon and trying the following code. > > But getting the following error. > > Please help me in knowing the code in better way. > > > OS Linux > Python version 2.7.13 > > > > def demo(s, exclaim): > #""" > # Returns the string 's'

Re: [Tutor] Remove soft line break

2019-02-04 Thread Peter Otten
Valerio Pachera wrote: > > I have a file with row that split at the 80th character. > The next row start with a blank space, meaning that i part of the previous > row. > > Example: > > Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam non justo > enim. Viv > amus dapibus quis neque

Re: [Tutor] python-files

2019-01-27 Thread Peter Otten
Asad wrote: > Hi All , > > I tried the following code : > > parser = argparse.ArgumentParser() > parser.add_argument("first") > parser.add_argument("second", nargs="?") > args = parser.parse_args() > print("first:", args.first) > > print("second:", args.second) > > When I execute

Re: [Tutor] python - files

2019-01-27 Thread Peter Otten
Cameron Simpson wrote: > Mats has mentioned the modules getopt and argparse etc. These are > primarily aimed at option parsing ("-v", "-o foo"). Your situation > occurs _after_ the option parsing (in your case, there are no options). Not argparse. The main advantage over optparse is its handling

Re: [Tutor] exporting lists into CSV issue.

2019-01-22 Thread Peter Otten
mhysnm1...@gmail.com wrote: > Now I am > trying to export to a CSV file. There is no syntax or logical errors I can > see. The information is being exported to the CSV. But when I bring it > into Excel. I am getting a blank row between each row. > with open ('books-list.csv', 'w') as wf: Try

Re: [Tutor] Importing XML files.

2019-01-21 Thread Peter Otten
mhysnm1...@gmail.com wrote: > I am trying to import ITunes XML files. I have been doing some reading and > I am somewhat confused with some XML terminology. > What is: > > > > Tag – I think it is the in the itunes library file. > > Text = The text between the > > Attrib -- don’t know. >

Re: [Tutor] Implementation of list comparison operators

2019-01-17 Thread Peter Otten
David Rock wrote: > >> On Jan 17, 2019, at 13:40, Peter Otten <__pete...@web.de> wrote: >> >> David Rock wrote: >> >>> >>> Isn’t this a bit artificial, though? The reason this is False is >>> because >>> you explicitly

Re: [Tutor] Implementation of list comparison operators

2019-01-17 Thread Peter Otten
David Rock wrote: > >> On Jan 17, 2019, at 12:39, Peter Otten <__pete...@web.de> wrote: >> >> One obscure detail of the implementation of list equality: >> >> In Python an object can be unequal to itself: >> >>>>&g

Re: [Tutor] Implementation of list comparison operators

2019-01-17 Thread Peter Otten
One obscure detail of the implementation of list equality: In Python an object can be unequal to itself: >>> class A: ... def __eq__(self, other): return False ... >>> a = A() >>> a == a False However, the list assumes that (a is a) implies a == a, so >>> [a] == [a] True

[Tutor] Implementation of list comparison operators, was Re: Doubt in Python

2019-01-17 Thread Peter Otten
Alan Gauld via Tutor wrote: > On 17/01/2019 07:24, Maninath sahoo wrote: > a=[100,50,30] > b=[100,90,3] > a > True > a>b > > False > > > > >> How it compares between two lists >> > The algorithm is probably described somewhere in the documentation > but my understanding is

Re: [Tutor] Debugging a sort error.

2019-01-13 Thread Peter Otten
mhysnm1...@gmail.com wrote: > Issue, following error is generated after trying to sort a list of > strings. > > description.sort() > TypeError: unorderable types: float() < str() Consider >>> descriptions = ["foo", "bar", 123, 3.14, 42, 200.1, "0"] >>> sorted(descriptions) Traceback (most

Re: [Tutor] Doubt

2019-01-07 Thread Peter Otten
Amit Yadav wrote: > How can simply typing > > print "hello world" > > work? > Like without including any header file or import statements how can it > work. In Python 2 print is part of the syntax that the compiler knows, just like int or for (... ) {} in C. In Python 3 print is just a

Re: [Tutor] Log file for Nested if-elif

2019-01-03 Thread Peter Otten
Asad wrote: > Hi All , > > Need advice on the following piece of code : > > with open(r"file1.log", 'r') as f: > tail = deque(maxlen=8) # the last eight lines > script = None > for line in f: > tail.append(line) > if >

Re: [Tutor] Defining variable arguments in a function in python

2018-12-30 Thread Peter Otten
Avi Gross wrote: > To spare others, Thank you for that. > I sent Steven alone 'Tis well deserved ;) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Defining variable arguments in a function in python

2018-12-29 Thread Peter Otten
Karthik Bhat wrote: > Hello, > > I have the following piece of code. In this, I wanted to make use > of the optional parameter given to 'a', i.e- '5', and not '1' > > def fun_varargs(a=5, *numbers, **dict): > print("Value of a is",a) > > for i in numbers: > print("Value

Re: [Tutor] Python script errors

2018-12-12 Thread Peter Otten
Ravi Kumar wrote: > Hi, > > I have developed a python script to get api calls for meraki > clientlogevents Thanks for all the help previously I am facing few errors > such as > > Json_string=r.json() > > raw_decode > raise JSONDecodeError("Expecting value", s, err.value) from None >

Re: [Tutor] Increase performance of the script

2018-12-12 Thread Peter Otten
Steven D'Aprano wrote: > [...] >> In python 2.6 print statement work as print "Solution" >> however after import collection I have to use print with >> print("Solution") is this a known issue ? > > As Peter says, you must have run > > from __future__ import print_function > > to see this

[Tutor] print statement vs print() function, was Re: Increase performance of the script

2018-12-11 Thread Peter Otten
Asad wrote: > Hi All, > > I used your solution , however found a strange issue with deque > : > > I am using python 2.6.6: Consider switching to Python 3; my code as posted already works with that. import collections d = collections.deque('abcdefg') print

Re: [Tutor] Increase performance of the script

2018-12-09 Thread Peter Otten
Asad wrote: > Hi All , > > I have the following code to search for an error and prin the > solution . > > /A/B/file1.log size may vary from 5MB -5 GB > > f4 = open (r" /A/B/file1.log ", 'r' ) > string2=f4.readlines() Do not read the complete file into memory. Read one line at a

Re: [Tutor] Finding the largest gap in tuple between two lists.

2018-11-18 Thread Peter Otten
Mats Wichmann wrote: > 1. From an endpoint pair - say Buy/Levski and Sell/Olisar, you need the > common items. No point in looking further at items that can't both be > bought at the source and sold at the destination. Fortunately, Python > sets are really good at this, but first you have to

Re: [Tutor] Problem using termcolor and colorama

2018-11-15 Thread Peter Otten
John Blower wrote: > I try to create colour text by using these two modules , only returns the > colour code, no colour text. How to solve this problem. > import termcolor import colorama colorama.init() termcolor.cprint('Hello World','red') > [31mHello World[0m Start with

Re: [Tutor] saveLine

2018-11-11 Thread Peter Otten
Avi Gross wrote: > Alan and others have answered the questions posed and what I am asking now > is to look at the function he proposed to keep track of the last five > lines. > > There is nothing wrong with it but I wonder what alternatives people would > prefer. His code is made for exactly 5

Re: [Tutor] Regex for Filesystem path (Asad)

2018-11-08 Thread Peter Otten
Albert-Jan Roskam wrote: > I was thinking it would also be possible to do (in Windows): > import os.path > os.path.sep = '/' > os.path.normpath('c:\\beeh/foo\\bar/baz') > > But alas, this still creates normalized windows-style paths. If your input data has only forward slashes you can keep it

Re: [Tutor] best way to dynamically set class variables?

2018-11-07 Thread Peter Otten
Alan Gauld via Tutor wrote: >>exec() might even be a way > > It's a way but it's a bad way! :-) And then > A simple approach you could use would be to get Python to > generate a new python file(module) containing the required class > definition (simple string processing) and then dynamically >

Re: [Tutor] How to print lines within two timestamp

2018-10-26 Thread Peter Otten
Alan Gauld via Tutor wrote: > On 26/10/2018 18:45, Alan Gauld via Tutor wrote: > >> It woiyukld > > No idea what happened there. Should be "would" of course! Of coiyukrse! Nobody thoiyukght otherwiiyske :) ___ Tutor maillist - Tutor@python.org To

Re: [Tutor] What is the best way for a program suite to know where it is installed?

2018-10-23 Thread Peter Otten
eryk sun wrote: > On 10/22/18, boB Stepp wrote: >> >> Importing the various program modules/module contents is >> no issue. Where I believe I need to know the paths to things are to >> get to data folders, config files, and occasionally utility programs >> that I have written that are on my

Re: [Tutor] Can tempfile.NamedTemporaryFile(delete=False) be used to create *permanent* uniquely named files?

2018-10-23 Thread Peter Otten
Cameron Simpson wrote: > On 21Oct2018 10:55, Peter Otten <__pete...@web.de> wrote: >>boB Stepp wrote: >>> So I am now wondering if using >>> tempfile.NamedTemporaryFile(delete=False) would solve this problem >>> nicely? As I am not very familiar with

Re: [Tutor] Some questions about importlib

2018-10-21 Thread Peter Otten
Quentin Agren wrote: > Hi, > > My name Quentin, and this is my first post to this list so please redirect > me if this is not the proper audience. > > I have been studying the 'importlib' standard library package this past > week, and although I find it very readable I am puzzled by some

Re: [Tutor] Can tempfile.NamedTemporaryFile(delete=False) be used to create *permanent* uniquely named files?

2018-10-21 Thread Peter Otten
boB Stepp wrote: > Use case: I want to allow a user of my Solitaire Scorekeeper program > to be able to give any name he wants to each game of solitaire he > wishes to record. My thought for permanent storage of each game's > parameters is to use a dictionary to map the user-chosen game names

Re: [Tutor] When are "__init__.py" files needed and not needed in a project?

2018-10-20 Thread Peter Otten
boB Stepp wrote: > Linux Mint 19 Cinnamon, Python 3.6.6 > > I would have sworn that I had read, either on this list or the main > Python list, that in the most recent versions of Python 3 that > "__init__.py" files were no longer needed in nested project file > structures. If you omit the

Re: [Tutor] How to find optimisations for code

2018-10-20 Thread Peter Otten
Steven D'Aprano wrote: > We don't need to check that the individual letters are the same, because > checking the counts will suffice. If they are not the same, one string > will have (let's say) two A's while the other will have none, and the > counts will be different. Another great

Re: [Tutor] How to find optimisations for code

2018-10-19 Thread Peter Otten
Pat Martin wrote: > So should we always use sets or dictionaries if possible? Are these more > efficient because of not keeping track of their position? Not always. If you want to know how often one entry/char occurs in a linear storage like a list, a string, or a file, then you can loop over

Re: [Tutor] How to find optimisations for code

2018-10-19 Thread Peter Otten
Mats Wichmann wrote: > On 10/19/2018 10:12 AM, Pat Martin wrote: >> Sorry my first email didn't have a subject line >> >> TLDR; How do you figure out if code is inefficient (if it isn't >> necessarily obvious) and how do you find a more efficient solution? > > I think you've hit it in your last

Re: [Tutor] How to find optimisations for code

2018-10-19 Thread Peter Otten
Pat Martin wrote: > Sorry my first email didn't have a subject line > > TLDR; How do you figure out if code is inefficient (if it isn't > necessarily obvious) and how do you find a more efficient solution? > > I use code wars sometimes to get some practice with Python, there was a > challenge

Re: [Tutor] problem with creating paths

2018-10-17 Thread Peter Otten
Shall, Sydney via Tutor wrote: > There are two items that are 'wrong' in this output. > > 1. The property 'paths' is defined in the program as a list and the > items are added using paths.append(), yet the test says that when tested > it is a tuple. >>> paths = ["foo", "bar"], >>> paths +=

Re: [Tutor] python game error

2018-10-15 Thread Peter Otten
Alan Gauld via Tutor wrote: > On 15/10/18 08:57, Peter Otten wrote: > >> By the way, you do not need a map (dict) at all to implement a game like >> this, you may return the next scene directly. A sketch: >> >> class Bridge: >> def enter(sel

Re: [Tutor] python game error

2018-10-15 Thread Peter Otten
bob gailer wrote: > Python coding "trick"1 > when I build a map I omit the () after the class e.g. 'death' = Death, > ... and apply them to the item retrieved from the map. > > use a decorator to build the map dictionary: > > # the decorator function: > def

Re: [Tutor] python game error

2018-10-13 Thread Peter Otten
Mariam Haji wrote: > Hi guys, > > I am still on the learn python the hard way. > I built the below on python 2.7 and my OS is windows 7. > > I am getting this error: > Traceback (most recent call last): > File "ex43.py", line 205, in > a_game.play() > File "ex43.py", line 21, in play >

Re: [Tutor] help please

2018-10-10 Thread Peter Otten
Michael Schmitt wrote: > To whom it may concern: > > > I am trying to teach myself Python and ran into a problem. This is my code > I am getting the following error > for rivers in rivers.values(): > AttributeError: 'str' object has no attribute 'values' > # prints river name > for rivers in

Re: [Tutor] [spoiler] Re: Shifting arrays as though they are a 'word'

2018-10-09 Thread Peter Otten
Chip Wachob wrote: > All, > > Sorry for not being more clear. I think I was nearing my fill of > Python for the day when I wrote. > > Now, refreshed, let me see if I can fill in the blanks a bit more. You have posted code sprinkled with prints and irrelevant details. Please rewrite the

Re: [Tutor] guess my number game (reversed)

2018-10-06 Thread Peter Otten
chiara pascucci wrote: > Hi, > > sorry for "resurrecting" this thread. I have tried doing as suggested but > with no luck. > I now managed to make the programme work "partially". It works as desired > for "too high" and "right" answer input, but when the users input "too > low" the programme

[Tutor] [spoiler] Re: Shifting arrays as though they are a 'word'

2018-10-06 Thread Peter Otten
Chip Wachob wrote: > Hello, > > I was not able to find any answers in the archive on this one. > > I'm wondering if this task can be done in a better way than what I've > attempted.. > > I have an array of bytes. Up to 64, which makes for 512 bits. > > I am reading these bytes in serially,

Re: [Tutor] Fwd: How to roughly associate the values of two numpy arrays, or python lists if necessary

2018-09-23 Thread Peter Otten
Peter Otten wrote: > Maybe you could sort the already-sorted property_b again, with some random > offset: > >>>> import itertools >>>> def wiggled(items, sigma): > ... counter = itertools.count() > ... def key(item): return random.gauss(next(counter

Re: [Tutor] Fwd: How to roughly associate the values of two numpy arrays, or python lists if necessary

2018-09-23 Thread Peter Otten
Shall, Sydney via Tutor wrote: > What I want is the following. > > I have: > > property_a = [1, 6, 2, 4] > > property_b = [62, 73, 31 102] > > Result should approximately be: > > property_b = [31, 102, 62, 73] > > That is both lists change in value in exactly the same order. > > Now, this is

Re: [Tutor] Help understanding base64 decoding

2018-09-13 Thread Peter Otten
Ryan Smith wrote: > Hello All, > > I am currently working on a small utility that finds any base64 > encoded strings in files and decodes them. I am having issue > understanding how the Base64 module actually works. The regular > expression that I am using correctly matches on the encoded

Re: [Tutor] Help with building bytearray arrays

2018-09-11 Thread Peter Otten
Chip Wachob wrote: > Peter, > > I see that clue "[[". > > The thread history pretty much sums up what is going on up to this point. > > I'll cover it once more: [snip] > I hope this helps. Unfortunately it doesn't as the problem is in my_transfer. > I'm beginning to wonder if Python was

Re: [Tutor] Help with building bytearray arrays

2018-09-10 Thread Peter Otten
Chip Wachob wrote: > Cameron, > > Thank you again for the insight. > > Yes, data_out is an equivalently-sized 'chunk' of a larger array. > > I'm 'getting' this now.. > > So, without all the fluff associated with wiggling lines, my function > now looks like this: > > def RSI_size_the_loop():

Re: [Tutor] Writing for loop output to csv

2018-09-07 Thread Peter Otten
Cameron Simpson wrote: > On 06Sep2018 12:32, Brandon Creech wrote: >>Hi, I am working to forecast the temperatures for the next 5 days using an >>API and a for loop. I would like write the output of this loop to a csv in >>this format:: >> >>Columns: City, min1, max1, min2,

Re: [Tutor] A Python program to Summarise weather results?

2018-08-30 Thread Peter Otten
Matthew Polack wrote: > Hi, > > We have a spreadsheet from a local weather station.it summarises the > amount of rainfall per day since 1863. > > http://www.bom.gov.au/jsp/ncc/cdio/weatherData/av?p_nccObsCode=136_display_type=dailyDataFile_startYear=1863_c=-1249186659_stn_num=079028 > >

Re: [Tutor] Problem compiling code from GitHub

2018-08-29 Thread Peter Otten
Dave Hill wrote: > I did as suggested but with the same result. Make sure that your script is *not* in the same directory as ODSWriter.py and that the directory containing ODSWriter is *not* in sys.path. Then try again. ___ Tutor maillist -

Re: [Tutor] need help generating table of contents

2018-08-27 Thread Peter Otten
Albert-Jan Roskam wrote: > > From: Tutor on behalf > of Peter Otten <__pete...@web.de> Sent: Friday, August 24, 2018 3:55 PM > To: tutor@python.org > >> The following reshuffle of your code seems to work: >> >> print('\r\n** Table of contents\r\n') >&

Re: [Tutor] need help generating table of contents

2018-08-24 Thread Peter Otten
Albert-Jan Roskam wrote: > Hello, > > I have Ghostscript files with a table of contents (toc) and I would like to use this info to generate a human-readable toc. The problem is: I can't get the (nested) hierarchy right. > > import re > > toc = """\ > [ /PageMode /UseOutlines > /Page 1 >

Re: [Tutor] Times Tables Program that constantly tells you that you are wrong!

2018-08-23 Thread Peter Otten
Matthew Polack wrote: > I'm also trying to solve the rounding issue...but can't work out the > syntax using the example provided...have tried this but I get an error... > > _tkinter.TclError: unknown option "-text %.2f" > > .I'm sure it is a simple syntax issue...but I don't know what it is. >

Re: [Tutor] Times Tables Program that constantly tells you that you are wrong!

2018-08-23 Thread Peter Otten
Matthew Polack wrote: > I'm working my way through some of the tips you provided and tried to use > the code givenbut am getting an error at Line 75 in my code re: not > enough arguments for format string > > _ > return self.func(*args) > File "Timespicture.py", line 75, in

Re: [Tutor] Times Tables Program that constantly tells you that you are wrong!

2018-08-16 Thread Peter Otten
Matthew Polack wrote: > Hi All, > > Thanks to your help I've nearly got my demo 'Times Tables' program fully > working. > > The last remaining issue is the program does not calculate the percentage > right when you make mistakes...it just keeps giving a result of 100%. > > I've looked and head

Re: [Tutor] Times Tables Program that constantly tells you that you are wrong!

2018-08-15 Thread Peter Otten
Matthew Polack wrote: > *Question 2:* > Is there a way to centre text within the text frame? I can change the font > and size...but don't know how to centre it? Ok, I wanted to know it myself, and found https://stackoverflow.com/questions/42560585/how-do-i-center-text-in-the-tkinter-text-widget

Re: [Tutor] Times Tables Program that constantly tells you that you are wrong!

2018-08-15 Thread Peter Otten
Matthew Polack wrote: > *Question 1:* > > *Why cant the program check if 'answer' variable is correct?* Change the line result = "Sorry...you were wrong. in your script to result = "Sorry...you were wrong. Expected {!r}, but got {!r}".format(answer, response) and find out

Re: [Tutor] Query: lists

2018-08-14 Thread Peter Otten
Alan Gauld via Tutor wrote: > On 14/08/18 09:11, Deepti K wrote: >> when I pass ['bbb', 'ccc', 'axx', 'xzz', 'xaa'] as words to the below >> function, it picks up only 'xzz' and not 'xaa' > > Correct because > >> def front_x(words): >> # +++your code here+++ >> a = [] >> b = [] >>

Re: [Tutor] Counting the # of iterations OR storing # values in a list

2018-08-13 Thread Peter Otten
Gautam Desai wrote: > I am currently working with the lattice.py code attached. The code is a > simulation that models the interactions between bacteria by producing a > lattice output. > > Once you run the code, there should be both blue and red bacteria that > show > on a lattice. I can

Re: [Tutor] Removing duplicates

2018-08-02 Thread Peter Otten
Oscar Benjamin wrote: > On 1 August 2018 at 21:38, Roger Lea Scherer wrote: >> >> 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

Re: [Tutor] SSL Error

2018-07-31 Thread Peter Otten
Saket Mehrotra wrote: > Hi > > I am trying to run import requests in a py file but I am getting below > error ssl.PROTOCOL_SSLv23: OpenSSL.SSL.SSLv23_METHOD, > AttributeError: module 'ssl' has no attribute 'PROTOCOL_SSLv23' If you start the Python interpreter and execute >>> import ssl >>>

Re: [Tutor] How to add an Image in Grid mode with Python and Tkinter?

2018-07-30 Thread Peter Otten
Matthew Polack wrote: > Hi, > > Steadily trying to learn Python and Tkinter here with our students... > > Am working on a simple 'Price of Cereal Crop' calculatorand have made > a start with the code below... > > I'm trying to simply add an image to our program to make the GUI more >

Re: [Tutor] Dictionary viceversa

2018-07-30 Thread Peter Otten
Zachary Ware wrote: > On Mon, Jul 30, 2018 at 12:20 PM Valerio Pachera wrote: >> I was looking to substiture the cicle for e in new_d like this: >> [ new_d[e].append(k) if e in new_d else new_d[e].append(k) for e in >> [ d[k] ] >> but it can't work because 'new_d[e] = []' is missing. > >

Re: [Tutor] Stuck on some basics re floats

2018-07-18 Thread Peter Otten
Matthew Polack wrote: > Hi, > > I'm a teacher trying to learn Python with my students. > > I am trying to make a very simple 'unit calculator' program...but I get an > error ..I think python is treating my num1 variable as a text string...not > an integer. > > How do I fix this? > > Thanks! >

Re: [Tutor] CSV Read

2018-06-30 Thread Peter Otten
Giulia Marcoux wrote: > Hello, > > I am a student learning python, and i am running into some difficulties. I > am tryign to read a csv file that has different delimiters for different > rows: Example: > > Format:V1.1 > Model: R > Step Size: 10mm > Distance: 10cm > Gain: 1000 > > X,Y > 1,3 >

Re: [Tutor] adding numpy to pandas

2018-06-21 Thread Peter Otten
Mats Wichmann wrote: > On 06/20/2018 02:04 PM, Glenn Schultz wrote: >> All, >> >> I have a pandas dataframe and a predict result (numpy array) of a >> classifier [[0,1],[1,0]]. What I would like to do is as the positive to >> the pandas dataframe. I use predict[:,1] to slice the postive from

  1   2   3   4   5   6   7   8   9   10   >