Re: [Tutor] Error Python version 3.6 does not support this syntax.

2018-11-29 Thread Cameron Simpson
you're working in bytes or text (str). Keep the division clean, that way all you other code can be written appropriately. So: the command pipe output is bytes. COnvert it to text before passing to your text parsing code. That way all the parsing code can work in text (str) and have no we

Re: [Tutor] I need help with my project

2018-11-30 Thread Cameron Simpson
, and the output from your programme - a complete transcript of any error message, for example if your programme raised an exception Make sure these are inline in your message, _not_ attachments. We drop attachments in this list. Cheers, Cameron Simpson _

Re: [Tutor] To check for empty string after a portion of the string in python 3.6

2018-12-03 Thread Cameron Simpson
MAC, value the name). Return the dictionary. If the dictionary is empty, there were no devices. Not that like almost all collections, empty dictionaries are "false", so you can go: bluetooth_devices = scanner.bluetooth_scan() if not bluetooth_devices: ... no devices found ... C

Re: [Tutor] To check for empty string after a portion of the string in python 3.6

2018-12-03 Thread Cameron Simpson
()) File "/home/srinivasan/Downloads/bt_tests/qa/test_library/Bt.py", line 74, in bluetooth_scan print("the value", res[1]) IndexError: list index out of range Well, you've printed your list: ['Scanning ...'] It is a single

Re: [Tutor] Trouble in dealing with special characters.

2018-12-08 Thread Cameron Simpson
f range characters -- ordinals >= 256 -- in a "byte" string). Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] decomposing a problem

2018-12-25 Thread Cameron Simpson
oosely speaking, safe: thread1: print(sorted(object)) thread2: print(sorted(object,reverse=True)) Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/m

Re: [Tutor] Debugging a sort error.

2019-01-13 Thread Cameron Simpson
t, not it cannot be current.) But first, fine out what's wrong. Try the type test I suggest and see how far you get. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Debugging a sort error.

2019-01-14 Thread Cameron Simpson
ext pattern exercise which I always have struggled with. Last language I did this in was Perl and had all sorts of headaches. ๐Ÿ˜Š Python seems cleaner from the reading I have done thus far. Lets see what challenges wait in front of me. I used to use Perl extensively. I put off moving to Python for

Re: [Tutor] python - files

2019-01-26 Thread Cameron Simpson
sability: the above code complains about each issue it encounters, and finally quits with an additional message. In a real programme that addition message would include a "usage" message which describes the expected arguments. Cheers, Cameron Simpson

Re: [Tutor] python - files

2019-01-27 Thread Cameron Simpson
On 27Jan2019 10:30, Peter Otten <__pete...@web.de> wrote: 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, th

Re: [Tutor] How to use "curses.resizeterm(nlines, ncols)"

2019-02-23 Thread Cameron Simpson
iced). Does this clarify things for you? Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How to use "curses.resizeterm(nlines, ncols)"

2019-02-24 Thread Cameron Simpson
On 24Feb2019 14:30, boB Stepp wrote: On Sun, Feb 24, 2019 at 1:39 AM Cameron Simpson wrote: It looks like the resizeterm() function updates the curses _internal_ records of what it believes the physcial terminal size to be. When you physically resize a terminal the processes within it

Re: [Tutor] How to use "curses.resizeterm(nlines, ncols)"

2019-02-24 Thread Cameron Simpson
notices changes automatically then it is uncommon to need to call resizeterm(). Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How to use "curses.resizeterm(nlines, ncols)"

2019-02-24 Thread Cameron Simpson
s_term_resized, resizeterm and the "internal" resize_term functions are recent additions :-) From "man 3 resizeterm": This extension of ncurses was introduced in mid-1995. It was adopted in NetBSD curses (2001) and PDCurses (2003). Cheers, Cameron Simpson

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

2019-02-26 Thread Cameron Simpson
eFilm(name, platform, dateAdded, tpe): return Film(name, platform, dateAdded) Unless there's more stuff happening in these functions which you've stripped out for clarity you could just call the object constructors directly from the if statements: if data['tpe'] == 'Game': a = Game(name, platform, dateAdded) game = {a: tpe} media.append(game) Why would I only get one object in media, even though all three are created? As you may gather, all three input lines are processed, but only one gets turned into an object to add to media. Change the if/if into an if/elif/else and see if things become more obvious. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Exception not working as expected?

2019-03-01 Thread Cameron Simpson
ust the one from the int() call, so it needn't indicate bad user input, it could as easily indicate some subsequent bug in your code, as many functions can raise ValueError if they are handed something unsatisfactory. Cheers, Cameron Simpson ___

Re: [Tutor] Is this the preferred way to change terminal screen color using curses?

2019-03-02 Thread Cameron Simpson
er on the screen is changed to the new background rendition. ยท Wherever the former background character appears, it is changed to the new background character. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Is this the preferred way to change terminal screen color using curses?

2019-03-02 Thread Cameron Simpson
quot;) contains only the library, not header files or doco wanted for development. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] systemd

2019-03-03 Thread Cameron Simpson
and learn... The octothorpe is only a comment marker at the start of a word. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] directory structure with tests?

2019-03-06 Thread Cameron Simpson
ou tell me what kind of system you have? For variety, in my own code I keep the tests for foo.py in foo_tests.py, the better to be seen next to foo.py in listings and file completion. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To u

Re: [Tutor] (no subject)

2019-03-22 Thread Cameron Simpson
lues: would be accepted. Which may be ok, and it should certainly be ok for your first attempt: tighten things up later. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] properly propagate problems

2019-03-23 Thread Cameron Simpson
tartswith('/'): raise ValueError("must be an absolute path") with open(input_file, 'rb') as f: return io.BytesIO(f.read()) Because of the Pfx the ValueError gets the input_file value in question prefixed automatically, so you don

Re: [Tutor] How to avoid "UnboundLocalError: local variable 'goal_year' referenced before assignment"?

2019-03-23 Thread Cameron Simpson
as defined: the scope at the bottom of your programme. This is called a "closure": functions has access to the scope they are define in for identifiers not locally defined (eg in the parameters or the function local variables - which are those assigned to in the code). This means you

Re: [Tutor] How to avoid "UnboundLocalError: local variable 'goal_year' referenced before assignment"?

2019-03-24 Thread Cameron Simpson
nested functions, but did not know it worked for lambdas as well. Lambda are functions. Same rules. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] operate on files based on comparing filenames to today's date

2019-03-28 Thread Cameron Simpson
roup(1,2,3,4) year = int(year) month = int(month) day = int(day) # turn this into a datetime.date object date = datetime.date(year, month, day) and return the computed date. Then just keep this in the for loop so it is obvious what's going

Re: [Tutor] Python Django Query

2019-04-01 Thread Cameron Simpson
quot;Using Django" list there. There's a guideline to posting here: https://code.djangoproject.com/wiki/UsingTheMailingList but your post looks fairly good on the face of it. Hoping this helps, Cameron Simpson Objective : display main page with multiple links to other pages. Use j

Re: [Tutor] Trouble with SUM()

2019-04-20 Thread Cameron Simpson
=0, /) Return the sum of a 'start' value (default: 0) plus an iterable of numbers When the iterable is empty, return the start value. This function is intended specifically for use with numeric values and may reject non-numeric types. Cheers, Cameron Simpson __

Re: [Tutor] self.name is calling the __set__ method of another class

2019-04-29 Thread Cameron Simpson
foo = Foo() print("age =", foo.age) @property arranges this using descriptors: in the example above it arranges that the class "age" attribute is a descriptor with a __get__ method. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] pip issue

2019-05-02 Thread Cameron Simpson
aged install and just do it all from scratch. I suspect this has something to do with me interrupting the install process, because I interrupted it precisely when it was fetching the package that it can't find now. Let me know if I should be asking this elsewhere. Thi

Re: [Tutor] Finding unique strings.

2019-05-03 Thread Cameron Simpson
simply the row from the CSV data as a first cut). The nice thing about a namedtuple is that the values are available as attributes: you can use "key.flavour" etc to inspect the tuple. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

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

2019-05-08 Thread Cameron Simpson
_date[date] += 1 A defaultdict is a dict which magicly makes missing elements when they get access, using a factory function you supply. Here we're using "int" as that factory, as int() returns zero. I presume you've got the timestamp => date conversion

Re: [Tutor] Looking for some direction

2019-05-11 Thread Cameron Simpson
The biggest change you'll find coming from Java is likely the typing: Python _values_ are strongly typed, but the variables are not - they can refer to a value of any type. And there aren't really Java interfaces. However, there are lint tools to look for issues like this. Oh yes:

Re: [Tutor] Looking for some direction

2019-05-12 Thread Cameron Simpson
se cut/paste is very fast (iTerm3 has a mode like most X11 apps: select implicitly copies, so no Cmd-C copy keystroke for me either). Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Two Scripts, Same Commands, One Works, One Doesn't

2019-05-15 Thread Cameron Simpson
dy of the message. Googling has not helped me to find a solution [...] 1: I recommend duckduckgo instead of Google for privacy/tracking reasons. 2: When I search, I tend to find people with the same problem, not necessarily people with answers. But this question might be hard to get

Re: [Tutor] I'm having a small problem with my code

2019-05-23 Thread Cameron Simpson
(look it up). But a since pass over the list isn't enough to sort the whole thing. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] File extension against File content

2019-05-31 Thread Cameron Simpson
//github.com/threatstack/libmagic 3: https://pypi.org/project/python-magic/ 4: https://pypi.org/search/?q=magic Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] is this doable

2019-05-31 Thread Cameron Simpson
in a local file. It is hard to be any more specific without knowing what you consider a task, and how you'd check if it was active. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Interactive editing of variables.

2019-05-31 Thread Cameron Simpson
Windows dropins for this facility. Maybe install this package: https://pypi.org/project/pyreadline-ais/ maybe with "python -m pip install pyreadline-ais". Then use it according to the documentation for the stdlib readline module: https://docs.python.org/3/library/readline.html#mo

Re: [Tutor] is this doable

2019-06-01 Thread Cameron Simpson
't yours. There should be a Windows equivalent for probing a process. The converse part where you start the process includes this: P = subprocess.Popen(.) # start the program with open(pid_filename, 'w') as pidf: print(P.pid, file=pidf) to update the process id fi

Re: [Tutor] regular expression query

2019-06-09 Thread Cameron Simpson
if m: category = m.match(1) id_number = m.match(2) recipient = m.match(3) else: m = re.match(...) ... more tests here ... ... ... else: ... report unmatched line for further consideration ... 3: You use ".*" a lot. This is quite prone to matching too much. You might find things like "\S+" better, which matches a single nonwhitespace "word". It depends a bit on your input. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Python printing parentheses and quotes

2019-06-10 Thread Cameron Simpson
his list drops attachments). That we we can all run exactly the same code, and solve your actual problem. And start always using: from __future__ import print_function in Python if you're using print. That will make your prints behave the same regardless if whether they are using Python 2 or 3. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Broadcasting using sockets over adhoc wifi

2019-06-13 Thread Cameron Simpson
e of the other Pis? Though given "Network is unreachable" I'd guess no packets get sent at all. I repeat my disclaimer: I've not used an ad hoc wifi network. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] deleting elements out of a list.

2019-06-15 Thread Cameron Simpson
: words = text.split() for i in enumerate(words): Word = ' '.join(words[:i]) print (word) answer = input('Keep word (ynq)?') if answer == 'n': continue elif answer = 'q': break for i, v in enumerate(description): if word in description[i]: description.pop[i] The inner for loop still has all the same issues as before. The outer loop is now more robust because you've iterating over the copy. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Differences between while and for

2019-06-15 Thread Cameron Simpson
ly true. In the extreme case you just treat the first loop specially: first = True while first or the-actual-condition: ... do stuff ... first = False if you want to use "first" during the "do stuff". Or you could be a bit more reliable and go: first_test = True

Re: [Tutor] Unexpected result when running flask application.

2019-06-19 Thread Cameron Simpson
at this point. He has, as it happens, over in fl...@python.org. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] data structures general query

2019-06-26 Thread Cameron Simpson
ly depending on what data structure is used to arrange the data, because some actions are cheap in some structures and expensive in others, so you choose the efficient action where possible. Cheers, Cameron Simpson ___ Tutor maillist - Tut

Re: [Tutor] Python and DB

2019-06-27 Thread Cameron Simpson
you'd need an SQLite library for PHP, but I cannot believe that one does not exist. (Or you could also write your web application in Python instead of PHP.) Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or chan

Re: [Tutor] Environment variables and Flask

2019-06-28 Thread Cameron Simpson
ing to Flask and the environment: because a Flask app is often invoked from within a web server instead of directly, it isn't feasible to pass it "command line" arguments to control it. So the environment becomes the most convenient place for ad hoc special settings. Cheers, Cameron

Re: [Tutor] Make a linked list subscriptable?

2019-07-11 Thread Cameron Simpson
as found. To turn all this into a subscriptable list, define the __getitem__ method as a function accepting an index. If that index is an int, just return that element. If the index is a slice (start:stop:stride), call the more complicated function to return multiple elements.

Re: [Tutor] Multiprocessing with many input input parameters

2019-07-12 Thread Cameron Simpson
does one write a one element tuple? Like this: (9,) Here the trailing comma is _required_ to syntacticly indicate that we intend a 1 element tuple instead of a plain "9 in parentheses") as in the earlier assignment statement. I'm not sure an

Re: [Tutor] raising exceptions in constructor code?

2019-07-16 Thread Cameron Simpson
your initialiser cannot complete correctly. Consider: x = Foo() After this assignment we expect "x" to be a usable instance of Foo. We don't put special checks; what would such checks look like? (There are some answers for that, but they're all poor.)

Re: [Tutor] Python code

2019-08-01 Thread Cameron Simpson
uot;py" command (I'm not on Windows here). So it may be that when you issue the command "python" it isn't running the Python interpreter but something else. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Difference between decorator and inheritance

2019-08-02 Thread Cameron Simpson
r would not have a callable to work with; it would get the None that your @collect returns. This is the other argument for always returning a callable: to interoperate with other decorators, or of course anything else which works with a callable. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Name for this type of class?

2019-08-02 Thread Cameron Simpson
ven your description. Unless they're snapshots/samples, in which case "Telemetric" ?-) Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Error terminal

2019-08-07 Thread Cameron Simpson
re precise than loose verbal descriptions alone). Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] HELP PLEASE

2019-08-13 Thread Cameron Simpson
message. If you move your misplaced "return to_ints(nums), to_ints(nums2)" statement up into the get_numbers function you should be better off, because then it will return a list of numbers, not strings. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] class functions/staticmethod?

2019-08-13 Thread Cameron Simpson
x27;m getting an area function from a nicely named class. (Also, I wouldn't have to import the area function explicitly - it comes along with the class nicely.) So the static method is used to associate it with the class it supports, for use when the caller doesn't have an instance to

Re: [Tutor] class functions/staticmethod?

2019-08-13 Thread Cameron Simpson
On 14Aug2019 11:15, Steven D'Aprano wrote: On Wed, Aug 14, 2019 at 09:58:35AM +1000, Cameron Simpson wrote: On 11Aug2019 22:58, James Hartley wrote: >I am lacking in understanding of the @staticmethod property. >Explanation(s)/links might be helpful. I have not found the descript

Re: [Tutor] Is nesting functions only for data hiding overkill?

2019-08-21 Thread Cameron Simpson
ting out that they should not I think you're not using "nesting" the way I think of it. Can you provide an example bit of code illustrating what you're thinking of and explaining your concerns? Also, your paragraph looks a little truncated.

Re: [Tutor] Chunking list/array data?

2019-08-22 Thread Cameron Simpson
e: int) -> list: return ( lst[x:x+size] for x in range(0, len(lst), size) ) Omitting the square brackets turns this into a generator expression. It returns an iterator instead of a list, which functions like the generator function I sketched, and generates the c

<    1   2   3   4