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

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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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-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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] (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] 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] 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] 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] 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] 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] 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] 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] 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
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-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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] Issue in using "subprocess.Popen" for parsing the command output

2018-11-25 Thread Cameron Simpson
.. print(s, file=sys.stderr) raise i.e. report some special message, then _reraise_ the original exception. In this way he gets to keep the original exception and traceback for debugging, which still making whatever special message he wanted to make. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] [Python 3] Threads status, join() and Semaphore queue

2018-11-24 Thread Cameron Simpson
code using your example and give it another try, I will make sure to let you know if I run into any issues or additional questions. :) Questions are welcome. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscri

Re: [Tutor] [Python 3] Threads status, join() and Semaphore queue

2018-11-19 Thread Cameron Simpson
r thread in threadPool: sem.acquire() thread.start() # wait for collection to complete collector.join() def collect(q, ids): for count in range(len(ids)): id = q.get() sem.release() so that you acquire the semaphore before starting each thread, and release the semaphore as thr

Re: [Tutor] GPA calculator

2018-11-14 Thread Cameron Simpson
above. It is useful so that people know what various discussions are about. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Example for read and readlines() (Asad)

2018-11-13 Thread Cameron Simpson
ing1[j-1]) a = mo.group() print a print os.getcwd() break Please advice how to proceed. mo.group() returns the whole match. The above seems to look for the string 'ERR2' in a line, and look for a patch number in the previous line. I

Re: [Tutor] Displaying Status on the Command Line

2018-11-07 Thread Cameron Simpson
see something weird. And I have no idea what happens on Windows. I'd sort of expect Windows terminals, even cmd.exe, to accept the ANSI sequences, which is what vt100 and xterms use. But that is expectation, not knowledge. Cheers, Cameron Simpson _

Re: [Tutor] Displaying Status on the Command Line

2018-11-07 Thread Cameron Simpson
viously contrived, and the sleeps are so you can see it all happen. But you can slot this into simple terminal based programmes to present dynamic progress. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change su

Re: [Tutor] Request for help with code

2018-11-06 Thread Cameron Simpson
On 06Nov2018 15:50, Joseph Gulizia ", count) You should see that the expected code is actually reached and run, and if it isn't, the corresponding print()s do not happen. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To u

Re: [Tutor] Request for help with code

2018-11-06 Thread Cameron Simpson
quot;, count, "target_int =", target_int) ... read the int ... if isint == True: print("isint is true!") ints.append(new_int) count += 1 print("count =>", count) You should see that the expected code is actually reached and run

Re: [Tutor] Regex for Filesystem path

2018-11-06 Thread Cameron Simpson
u can find that with os.path.getctime() (or several >other options, eg os.stat) Do not use ctime, it is _not_ "creation" time. It is "last change to inode" time. It _starts_ as creation time, but a chmod or even a link/unlink can change it: anything that changes the metad

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

2018-10-23 Thread Cameron Simpson
On 23Oct2018 11:24, Peter Otten <__pete...@web.de> wrote: Cameron Simpson wrote: The doco for mktemp (do not use! use mkstemp or the NamedTemporaryFile classes instead!) explicitly mentions using delete=False. Well, "permanent temporary file" does sound odd. By the way, Na

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

2018-10-22 Thread Cameron Simpson
ts of the config file". Which lets the user keep a tiny config file modifying only the stuff which needs tweaking. Utilities: I my opinion, unless they shift with you app it is the end user's job to have these in the execution path ($PATH on UNIX). If you app/packag

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

2018-10-21 Thread Cameron Simpson
classes instead!) explicitly mentions using delete=False. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

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

2018-10-21 Thread Cameron Simpson
n all operating systems? The doco reads that way to me. However, NamedTemporaryFile is a (nice) wrapper for tempfile.mkstemp(). Why not use that directly? Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subsc

Re: [Tutor] How to find optimisations for code

2018-10-19 Thread Cameron Simpson
eneficial to inspect. It at least gets you objective information about where your programme spends its time. It is limited by the data you give your programme: toy example input data are not as good as real world data. Finally, some things are as efficient as they get. You _can't_ always

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

2018-10-05 Thread Cameron Simpson
vert back into bytes. The easy way is to just accrue the bytes into a value as you read them: n = 0 for b in the_bytes: n = n<<8 + b if you're reading "big endian" data (high ordinal bytes come first). So read them in, accruing the value into "n".

Re: [Tutor] Help understanding base64 decoding

2018-09-13 Thread Cameron Simpson
ing of your target text => decode to a Python str Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Help with building bytearray arrays

2018-09-10 Thread Cameron Simpson
rns all_together returns So both are type 'list' which is referred to here : https://infohost.nmt.edu/tcc/help/pubs/python/web/sequence-types.html as a valid sequence type but apparently there's a detail I'm still missing... Yeah. byt

Re: [Tutor] Help with building bytearray arrays

2018-09-10 Thread Cameron Simpson
On 09Sep2018 23:00, Chip Wachob wrote: On Sat, Sep 8, 2018 at 9:14 PM, Cameron Simpson wrote: Actually he's getting back bytearray instances from transfer and wants to join them up (his function does a few small transfers to work around an issue with one big transfer). His earlier co

Re: [Tutor] Help with building bytearray arrays

2018-09-09 Thread Cameron Simpson
ay( (1,2,3,65,66) ) print(repr(bs)) print(hexlify(bs)) [...] faffing is a new term, but given the context I'm guessing it is equivalent to 'mucking about' or more colorful wording which I won't even attempt to publish here. You are correct: https://en.wikipedia.org/wi

Re: [Tutor] Help with building bytearray arrays

2018-09-08 Thread Cameron Simpson
7;foobah') And he's working with bytearrays because the target library is Python 2, where there's no bytes type. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Help with building bytearray arrays

2018-09-08 Thread Cameron Simpson
On 08Sep2018 20:01, Cameron Simpson wrote: So, if I'm understanding the transfer() function correctly, the function takes and returns a bytearray type. It would be good to see the specification for the transfer function. They we can adhere to its requirements. Can you supply a URL?

Re: [Tutor] Help with building bytearray arrays

2018-09-08 Thread Cameron Simpson
y Python 3 deals with chunks of bytes. A "bytes" is readonly and a bytearray may have its contents modified. From a C background, they're like an array of unsigned chars. I'm going to try the experiment you mentioned in hopes of it giving me a be

Re: [Tutor] Help with building bytearray arrays

2018-09-07 Thread Cameron Simpson
I'm obviously missing something fundamental here. Problem is I can't seem to find any examples of people asking this question before on the inter-webs.. You have the opposite of my problem. I can often find people asking the same question, but less often an answer. Or a decent answ

Re: [Tutor] Writing for loop output to csv

2018-09-06 Thread Cameron Simpson
weather = ForecastIO.ForecastIO( api_key, latitude=coords[0], longitude=coords[1] ) daily = FIODaily.FIODaily(weather) for day in range(2,7): day_data = daily.get_day(day) csvw.writerow([city, day_data['temperatureMax'], day_data['temperatureMin

Re: [Tutor] localhosting

2018-09-06 Thread Cameron Simpson
forum seems the nicest and most helpful I've encountered. The output of a CGI script should be a valid HTTP response: you need some HTTP headers describing the output format and _then_ the core programme output. The minimal header is a Content-Type: header to denote the program result for

Re: [Tutor] REG : Pexpect timeout issue

2018-09-01 Thread Cameron Simpson
On 02Sep2018 14:29, Steven D'Aprano wrote: On Sun, Sep 02, 2018 at 10:01:02AM +1000, Cameron Simpson wrote: On 02Sep2018 00:31, Steven D'Aprano wrote: >On Sat, Sep 01, 2018 at 11:41:42AM +, krishna chaitanya via Tutor >wrote: >>Below is my code, i am frequently hi

Re: [Tutor] REG : Pexpect timeout issue

2018-09-01 Thread Cameron Simpson
quot;su" and see if it matches your pattern. And so on. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] REG : Pexpect timeout issue

2018-09-01 Thread Cameron Simpson
it take to connect manually using ssh? He's not using ssh - it is all local. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] OT: How to automate the setting of file permissions for all files in a collection of programs?

2018-08-30 Thread Cameron Simpson
f he can mount a Solaris drive (NFS or SMB) he can just copy the files :-) Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] OT: How to automate the setting of file permissions for all files in a collection of programs?

2018-08-29 Thread Cameron Simpson
quot;export" from your WIndows git (or some mirror elsewhere). So: do you have rsync? Do you have ssh from your PC to the Solaris box? Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options:

Re: [Tutor] need help generating table of contents

2018-08-25 Thread Cameron Simpson
't have any way to extract semantics like titles from a document. The OP presumably has the specific output of a particular tool with this nice well structured postscript, so he needs to write his/her own special parser. Cheers, Cameron Simpson

Re: [Tutor] Query: lists

2018-08-14 Thread Cameron Simpson
ameters. When you pass values to Python functions, you are passing a reference, not a new copy. If a function modifies that reference's _content_, as you do when you go "words.move(z)", you're modifying the original. Try running this code: my_words = ['bbb'

Re: [Tutor] Do something on list elements

2018-07-27 Thread Cameron Simpson
ter). For example: with open(filename) as f: for lineno, line in enumerate(f, 1): if badness: print("%s:%d: badness happened" % (filename, lineno), file=sys.stderr) continue ... process good lines ... Cheers, Cameron Simpson __

Re: [Tutor] changing font

2018-07-13 Thread Cameron Simpson
? Then the tag might help you. Some other document format such as roff or LaTeX? A terminal? If this is possible it will be entirely terminal dependent. A GUI of some kind, such as Tk or Qt? You will need to consult its documentation for its text widgets. Cheers, Cameron Simpson (

Re: [Tutor] Virtual environment question

2018-03-11 Thread Cameron Simpson
e are other tools for the same purpose). In fact, tell us regardless. It aids debugging. Cheers, Cameron Simpson (formerly c...@zip.com.au) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] help with code

2018-03-11 Thread Cameron Simpson
sername") password = input("Please enter your password") Again, these lines should call raw_input(), not input(). def thank_you(): print("Thank you for signing up at our website!.") You define this function but never call it. elif choice == "q":

Re: [Tutor] Regex not working as desired

2018-02-26 Thread Cameron Simpson
e that you get an int back, which is easy to test for your other constraints (less than 1, greater than 0). Now, because int(0 raises an exception for bad input you need to phrase the test differently: try: value = int(digits) except ValueError: # invalid input, do something here

Re: [Tutor] unable to locate python on mac

2018-01-31 Thread Cameron Simpson
ather you use, is, I thought, just an editor. You also need somewhere to run Python from. Those of use not using IDEs generally run the programmes from a terminal. Personally I use iterm3 for my terminals, lots of nice features. Cheers, Cameron Simpson (formerly c...@zip.com.au) _

Re: [Tutor] Do _all_ Python builtin methods/functions return "None" IF ...

2018-01-27 Thread Cameron Simpson
method will usually return None. These modification methods _could_ return a value, but the general practice is not to. Cheers, Cameron Simpson (formerly c...@zip.com.au) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription

  1   2   3   4   >