Re: [Tutor] Use of "or" in a lambda expression

2015-04-04 Thread Cameron Simpson
t logic we have been discussing, or it would stop evaluating after the print statement return. Why is that? Because the list/tuple is constructed entirely before all() is called. All() operates only on the final values. Cheers, Cameron Simpson Yesterday, I was running a CNC plasma cutter that's

Re: [Tutor] Need some help with setuptools for my project.

2015-04-07 Thread Cameron Simpson
ls its "mcli" script like this: 'entry_points': { 'console_scripts': [ 'mcli = cs.app.megacli:main', ], Note the ":" before main, not ".". Cheers, Cameron Simpson I think... Therefore I ride. I ride... Ther

Re: [Tutor] Need some help with setuptools for my project.

2015-04-07 Thread Cameron Simpson
as you like. After you've made a virtualenv, running the "pip" it supplies will install into the virtualenv. Much safer, and you can do it all as yourself. Cheers, Cameron Simpson I made this letter longer than usual because I lack the time to make it shorter.-

Re: [Tutor] Why is it invalid syntax to have a particular dictionary value as an argument?

2015-04-07 Thread Cameron Simpson
that. Of course, when you print "d['a']" it must evaluate that then, and finds 'new value'. This is one reason why the common idion for default values looks like this: def func(s=None): if s is None: s = ... compute default here ... Of course, the default

Re: [Tutor] subprocess.Popen / proc.communicate issue

2017-03-30 Thread Cameron Simpson
derr=subprocess.PIPE) proc = subprocess.Popen(cmd_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) s,err=proc.communicate() s=s.strip() err=err.strip() if(err==0): try_='' It is preferable to say: try_ = False Also, you should be lookin

Re: [Tutor] subprocess.Popen / proc.communicate issue

2017-03-30 Thread Cameron Simpson
and understanding it when looking at this kind of problem. Cheers, Cameron Simpson On 31Mar2017 09:43, Cameron Simpson wrote: On 30Mar2017 13:51, bruce wrote: Trying to understand the "correct" way to run a sys command ("curl") and to get the potential stderr. Checki

Re: [Tutor] subprocess.Popen / proc.communicate issue

2017-03-31 Thread Cameron Simpson
On 31Mar2017 06:13, eryk sun wrote: On Thu, Mar 30, 2017 at 10:51 PM, Cameron Simpson wrote: This suggests that .communicate uses Threads to send and to gather data independently, and that therefore the deadlock situation may not arise. For Unix, communicate() uses select or poll. It uses

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

2017-04-01 Thread Cameron Simpson
elpful print() calls scattered throughout should show you what is going on, too. Note that it would also be prudent to prevent more than one start thread running, and so forth. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] bracket issue

2017-04-18 Thread Cameron Simpson
nto the "don't use regexps for this" domain. 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 %f and %F string formatting?

2017-04-27 Thread Cameron Simpson
formats rather than having to laboriously reproduce special stuff. Definitely a niche, and probably not the core motivation here. But handy. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscri

Re: [Tutor] Hi all: How do I save a file in a designated folder?

2017-05-02 Thread Cameron Simpson
prose, not in filenames. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Bug

2017-05-17 Thread Cameron Simpson
ot;, "X", "X"] or board[6:9]==["X", "X", "X"] or \ [board[0],board[3],board[6]]==["X", "X", "X"] or [board[1],board[4],board[7]]==["X", "X", "X"] or [board[2],board[5],board[8]] ==["

Re: [Tutor] Collecting output from Python scripts executed via Cron

2017-05-20 Thread Cameron Simpson
...@example.com Or, if you're using Vixie cron (very very common), set MAILTO in your crontab and let cron do the work: MAILTO=y...@example.com ... your-program.py Obviously "..." is your cron schedule values. Cheers, Cameron Simpson __

Re: [Tutor] threading tutorial

2017-05-25 Thread Cameron Simpson
t you started on one approach. Pausing can be done in a few ways, either by starting and stopping individual threads, one after another, or by starting one thread and using a mutex of some kind to cause it to suspend activity when needed. Yet anothe

Re: [Tutor] airflow dag

2017-05-27 Thread Cameron Simpson
ooks like a tool for data driven computation using a graph of data pipelines. By restricting it to a DAG on can be certain the computation will finish and the termination condition is trivially satisfied. No feedback loops. Cheers, Cameron Simpson ___

Re: [Tutor] Problem with if statements and else statements

2017-05-29 Thread Cameron Simpson
'): BTW, in Python we tend to use named like "Fred" for classes (or factories), and "fred" for regular variables. And "FRED" for things that would be constants in other languages. Eg: MAX_THINGS = 16 class Foo: def FooBah(x): return Foo(x,

Re: [Tutor] Problem with if statements and else statements

2017-05-30 Thread Cameron Simpson
On 30May2017 12:06, Peter Otten <__pete...@web.de> wrote: Cameron Simpson wrote: As written it should be a bit slower: to construct a set each member get tested for presence. The cost is in making the set, not in searching it. No, CPython is a bit smarter than that: dis.dis('

Re: [Tutor] f.readlines(size)

2017-06-06 Thread Cameron Simpson
the underlying I/O buffer size, but it does let you gather only the lines you want: you can count line lengths or numbers or whatever criteria you find useful if you want to stop be fore the end of the file. Cheers, Cameron Simpson ___ Tutor maillis

Re: [Tutor] Coming from R, what's a good IDE editor? I've tried PyCharm and Spyder

2017-06-08 Thread Cameron Simpson
n be turned off; mine doesn't do this. I also turned off the auto-comment-continuation. Anyway, somewhat off topic. -- Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] __str__ on a subclass

2017-06-19 Thread Cameron Simpson
ke the print(dev_1.dev_repr())? Assuming that when you say "the Employee subclass" above you mean "Developer", just like any other method you would override in a subclass. When you define Developer, define a __str__ method: class Developer(Employee): ... def __str__(s

Re: [Tutor] Desktop Notifications on Linux

2017-06-29 Thread Cameron Simpson
ure.py and have secure.py just read from standard input. This is that advantage that (a) the only root thing is the tail command, which just reads and (b) your program can produce alerts in real time as they come in from the tail, without having to write painful "tail"-like logic within the

Re: [Tutor] Fwd: Re: program code for Python Programming for the Absolute Beginner, 3rd ed.?

2017-07-03 Thread Cameron Simpson
shell before proceeding. Personally my practice is to mostly use pip only with virtualenvs, as myself. Using pip as root tends to conflict with Python packages supplied by the OS vendor/supplier; better to stay out of the way of that and work as oneself on data the OS vendor doesn't want to

Re: [Tutor] @property vs @classmethod

2017-07-08 Thread Cameron Simpson
Try modifying each method to print(repr(self)) as the first thing; you should see that for a normal method and a property "self" is the instance, for the classmethod it is the class, and that it isn't supplied at all for a staticmethod. Cheers, Cameron Simpson __

Re: [Tutor] Python Help

2017-07-22 Thread Cameron Simpson
lve them. The OP will need to use Python 2 because the module seems to rely on a relative import (for its "util.py" file). Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Quick Pythonic Style Tips

2017-07-23 Thread Cameron Simpson
amed, runs that script against whatever files are currently modified in my working code repo. So one can just say "lint" at the shell prompt to get a report on one's work in progress. Script appended below. Cheers, Cameron Simpson #!/bin/sh # # Lint the named files. # - Cameron

Re: [Tutor] Python help

2017-07-23 Thread Cameron Simpson
g you want the module to be at '../illustris_python/illustris_python'. See if using '/Users/Jim/Documents' finds the module. Then move it to a better (more targeted) directory and use that directory's name :-) Cheers, Cameron Simpson __

Re: [Tutor] Python Daemons

2017-08-02 Thread Cameron Simpson
have finished. By marking a Thread as a daemon you're saying that its activity is not important after program exit. This is probably not the case for your tutorial task. Like others, I recommend learning Python 3. It is broadly the same language bu

Re: [Tutor] file move with wait period

2017-08-03 Thread Cameron Simpson
es in the directory. For each name, record the file's size and modification time. Wait for that to be unchanged "long enough"; you might then decide it is ready to move. Cheers, Cameron Simpson (formerly c...@zip.com.au) ___ Tuto

Re: [Tutor] if __name__=='main' vs entry points: What to teach new comers?

2017-08-03 Thread Cameron Simpson
console_scripts? I have a bunch of "one liner" scripts in my personal "bin" directory like this one: #!/bin/sh # # Run the named port forwards indefinitely. # - Cameron Simpson 08jul2008 # # Convert to Python module cs.app.portfwd. - camer

Re: [Tutor] (no subject)

2017-08-03 Thread Cameron Simpson
gful. Your code above _should_ have an int in the value of "guess". However, I suspect your code actually may look like this: number=random.randint(1,20) guess=input() guess_value=int(guess) if guessi.e. I'm suggesting that you haven't put the int into "

Re: [Tutor] Unorderable types

2017-08-04 Thread Cameron Simpson
ue)) print("type(number) =", type(number)) above that line and run it again? Because I just ran your code here and it worked for me. Hope this can help you and mostly me I don't wanna give up but help is scarce from my location That's fine. The list is for

Re: [Tutor] Unorderable types

2017-08-04 Thread Cameron Simpson
original snippets included a: guess = int(guess) between those 2 lines. Anyway, we have his current code, which i can't made produce the error. Cheers, Cameron Simpson (formerly c...@zip.com.au) ___ Tutor maillist - Tutor@python.

Re: [Tutor] unorderable types

2017-08-06 Thread Cameron Simpson
usually always hold the same type of value; this storing of different types of values in the same variable contributed to your problem. 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] How does len() compute length of a string in UTF-8, 16, and 32?

2017-08-07 Thread Cameron Simpson
irst) or little-endian (least significant byte first). The machine I'm on here is writing big endian UTF-16 and UTF-32. As you note, the 16 and 32 forms are (6 + 1) times 2 or 4 respectively. This is because each encoding has a leading byte order marker to i

Re: [Tutor] Difference(s) betweenPython 3 static methods with and without @staticmethod?

2017-08-08 Thread Cameron Simpson
can call them on instances, and the caller doesn't need to know what style of method they are. The caller just goes: K.m(blah) and doesn't care. 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] Difference(s) betweenPython 3 static methods with and without @staticmethod?

2017-08-08 Thread Cameron Simpson
return klass(p.x, p.y, p.z) because it lets you subclass Foo: class Bah(Foo): and call Bah.from_point(p) for free, and it will make a Bah instead of a Foo because it gets the class as "klass". Cheers, Cameron Simpson (formerly c...@zip.com.au) ___

Re: [Tutor] How does len() compute length of a string in UTF-8, 16, and 32?

2017-08-08 Thread Cameron Simpson
On 08Aug2017 22:30, boB Stepp wrote: On Mon, Aug 7, 2017 at 10:20 PM, Cameron Simpson wrote: On 07Aug2017 21:44, boB Stepp wrote: py3: s = 'Hello!' py3: len(s.encode("UTF-8")) 6 py3: len(s.encode("UTF-16")) 14 py3: len(s.encode("UTF-32")) 28 How

Re: [Tutor] How does len() compute length of a string in UTF-8, 16, and 32?

2017-08-10 Thread Cameron Simpson
c reasons. I believe Eryk Sun is the go to guy for precise technical descriptions of the Windows situation. I'm not a Windows guy, but I gather modern Windows generally gives you a pretty clean UTF-8 environment in most situations. Cheers, Cameron Simpson (formerly c...@zip.com.au)

Re: [Tutor] "Path tree"

2017-08-15 Thread Cameron Simpson
ou in figuring out what is working and what is not. 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] "Path tree"

2017-08-16 Thread Cameron Simpson
On 16Aug2017 10:22, Alan Gauld wrote: On 16/08/17 02:02, Cameron Simpson wrote: Ok. So you have a graph like this: 1 -- 2 -- 3 -- 4 | 7 -- 5 -- 6 -- 8 graph = { 1: [2], 2: [1, 3], 2: [1, 3, 5], 3: [2, 4], 4: [3], 5: [7, 6], 5: [2, 6, 7

Re: [Tutor] help with subprocess module

2017-08-19 Thread Cameron Simpson
the log file, overwriting whatever was there. Which might be your problem. Others have made other remarks. I'm not sure any of your problems have to do with the subprocess module itself. Cheers, Cameron Simpson (formerly c...@zip.com.au) ___ Tut

Re: [Tutor] When to use classes

2017-08-19 Thread Cameron Simpson
nctions or methods of your own whose interfaces are your own operation, and which call the library to accomplish the task, providing some separation between a natural expression of your upper level problem and what you might write if you were building from the bottom and thinking in the librar

Re: [Tutor] Best way to get root project directory in module search path

2017-08-27 Thread Cameron Simpson
uot; shell function which prehacks $PYTHONPATH to have my local lib directory at the start of $PYTHONPATH. Again, the module itself can then trust that things are as they should be. Which is as it should be. Cheers, Cameron Simpson (formerly c...@zip.com.au)

Re: [Tutor] Best way to get root project directory in module search path

2017-08-27 Thread Cameron Simpson
On 27Aug2017 14:27, boB Stepp wrote: On Sun, Aug 27, 2017 at 2:13 AM, Cameron Simpson wrote: On 26Aug2017 21:27, boB Stepp wrote: import sys sys.path.append('..') [...] The trouble with this specific approach is that '..' relies on your _working_ directory being above

Re: [Tutor] Best way to get root project directory in module search path

2017-08-28 Thread Cameron Simpson
On 28Aug2017 20:39, boB Stepp wrote: On Sun, Aug 27, 2017 at 6:03 PM, Cameron Simpson wrote: from os.path import dirname It did not occur to me to import something from os.path to use sys.path! It is pretty normal to import specific names from modules rather than laboriously writing

Re: [Tutor] Select a string

2017-09-05 Thread Cameron Simpson
until the problem became glaringly obvious. BTW, it isn't good to write tests like: if theo == True: "theo" a Boolean anyway. Just say: if theo: It reads more naturally as well. Cheers, Cameron Simpson (formerly c...@zip.com.au)

Re: [Tutor] Select a string

2017-09-06 Thread Cameron Simpson
ularly for little state machines like yours I often find such descriptions useful. They help get the logic clear in my own mind _before_ writing the loop, and help you and others understand the code later when you come back to debug. It can also help to comment the individual if-statements. Eg

Re: [Tutor] How to write database-agnostic python code? (Is this even possible?)

2017-09-13 Thread Cameron Simpson
1 == 9 and t.col2 == 10) where "t" is a "table" object it has handed you. I believe these are just special objects with attributes for columns and the right __eq__ etc dunder methods to compute the correct SQL syntax. No escaping or param substitution in

Re: [Tutor] How to write database-agnostic python code? (Is this even possible?)

2017-09-14 Thread Cameron Simpson
eally need; that can have flow on effects as surrounding code might start to take advantage of the extra information more than required. Such code is harder to modify later because more semantics need to be preserved. Cheers, Cameron Simpson (formerly c...@zip.com.au) _

Re: [Tutor] Converting a string to a byte array

2017-09-24 Thread Cameron Simpson
ocumentation is silent on this, maybe use 'ascii' instead just on principle - better to notice in your program and decide what to do there than to feed garbage to your device and have is misbehave. 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] Converting a string to a byte array

2017-09-24 Thread Cameron Simpson
On 25Sep2017 09:29, Phil wrote: On 25/09/17 07:26, Cameron Simpson wrote: I don't understand why this works from the pyqt IDE but not when run from the console. I suppose the IDE is adding the correct encoding. I'm guessing the IDE is python 2 and not doing any encoding at all. I

Re: [Tutor] Converting a string to a byte array

2017-09-25 Thread Cameron Simpson
ing in the buffer, unsent. 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] Most common words in a text file

2017-09-30 Thread Cameron Simpson
arge. So one might process file file as lines of text: C = Counter() for line in textfile: words = line.lower().split() C.update(words) This avoids the need for more than a single line to be stored in memory at any given time. Cheers, Cameron Simpson (formerly c...@zip.com.au)

Re: [Tutor] Directory Structure

2017-09-30 Thread Cameron Simpson
our own policy instead of trying to do some kind of feature survey of stuff out there. 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] Tree again: iterator, yield, increase (treelib)

2017-10-14 Thread Cameron Simpson
In this way the whole tree is traversed. 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] confused about Pypi

2017-10-28 Thread Cameron Simpson
On 29Oct2017 10:13, Cameron Simpson wrote: On 28Oct2017 21:43, Mark Anderson wrote: Hello, I am currently doing an online course to learn Python. Generally ive followed it well and am enjoying my first go at programming. However the description of how to get modules from PyPi has left me

Re: [Tutor] confused about Pypi

2017-10-28 Thread Cameron Simpson
command prompt showing the prompt, your command and the complete error message. Cheers, Cameron Simpson (formerly c...@zip.com.au) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman

Re: [Tutor] How to handle passwords in programs that perform FTP processes?

2018-01-04 Thread Cameron Simpson
. Tradition ftp programs used to be able to use .netrc files, and this module reads them. It means storing credentials in the clear (obvious make the .netrc file 0600 permissions), but in most batch situations you're stuck with that anyway. Cheers, Cameron Si

Re: [Tutor] delete strings from specificed words

2018-01-10 Thread Cameron Simpson
swith('diff --git '): break interesting.append(line) Now the "interesting" list has the lines you want. There's any number of variations on that you might use, but that should get you going. Cheers, Cameron Simpson __

Re: [Tutor] delete strings from specificed words

2018-01-11 Thread Cameron Simpson
On 11Jan2018 12:16, YU Bo wrote: Hi, Hi, On Thu, Jan 11, 2018 at 11:40:35AM +1100, Cameron Simpson wrote: Do you have the text as above - a single string - or coming from a file? I'll presume a single string. En.., the text is multi-string from str(something) within python. Tha

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

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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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
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] 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] 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] 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] 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-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
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-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-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-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 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] 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] 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] 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] 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] 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-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] 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] 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] 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] 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] 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] 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] 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] [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] [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] 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

<    1   2   3   4   >