Re: [Tutor] python question

2019-08-18 Thread Steven D'Aprano
ia.org/wiki/Graph_theory -- Steven ___ 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 Steven D'Aprano
. Your lesson gives us no clue why James' first method, "dimensions()", which he describes as a "class method", isn't a class method and doesn't actually work correctly, even though it appears to at first glance. -- Steven __

Re: [Tutor] class functions/staticmethod?

2019-08-12 Thread Steven D'Aprano
return _dimensions If you are coming from a Java background, you may have been fooled by an unfortunate clash in terminology. A "static method" in Java is closer to a *classmethod* in Python, not a staticmethod. The main difference being that in Java, class variables (att

Re: [Tutor] class functions/staticmethod?

2019-08-12 Thread Steven D'Aprano
_dimensions = Dimensions(3, 4) @classmethod def dimensions(cls): print('id = {}'.format(id(cls._dimensions))) return cls._dimensions and now both Foo.dimensions() and Foo().dimensions() will work correctly, and as a bonus it ought to be a little faster. Part 3

Re: [Tutor] class functions/staticmethod?

2019-08-12 Thread Steven D'Aprano
t to receive "self" as the automatic first argument. That's pretty rare. For a very long time, the only known use for staticmethod was in the tests checking that the staticmethod code worked correctly. So that's what staticmethod does. It is occassionally useful, but no

Re: [Tutor] Create Logging module

2019-08-01 Thread Steven D'Aprano
n shot or photo and send that, instead copy and paste the text into your email. (P.S. please reply to the mailing list, not to me personally.) -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https:/

Re: [Tutor] Fw: CSC1010H 4th assignment

2019-07-25 Thread Steven D'Aprano
ments without crediting them is almost certainly a violation of your university's standards of academic ethics. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] A question about daunting KeyError

2019-07-24 Thread Steven D'Aprano
eyError: log(data) log(key) raise or use the debugger to investigate why the key is missing. You should also read this: http://sscce.org/ It is written for Java programmers, but it applies to Python too. -- Steven ___ Tutor ma

Re: [Tutor] Python Generator expressions

2019-07-23 Thread Steven D'Aprano
tuple inside a tuple: a = 1, 2, (3, 4, 5), 6 assert len(a) == 4 or when passing a literal tuple as argument to a function: function(1, 2, 3, 4, 5, 6)# six arguments function(1, 2, (3, 4, 5), 6) # four arguments -- Steven ___ Tutor maillist - T

Re: [Tutor] Python Generator expressions

2019-07-23 Thread Steven D'Aprano
st comprehensions are clearly useful, but tuple comprehensions not so much. Not ever single use has to get its own special syntax. Of course, *later on* once Python had generator comprehensions using parentheses, we couldn't easily add tuple comprehensions because there's no good s

Re: [Tutor] How to convert string to date time format?

2019-07-20 Thread Steven D'Aprano
On Fri, Jul 19, 2019 at 10:44:36PM -0400, C W wrote: > Hello all, > > I have a date time string that looks like the following. > > 02015-07-01 00:01:44.538420-08:00 > 12015-07-01 00:27:58.717530-08:00 > 22017-07-01 07:07:48.391376-08:00 I assume that the leading number and spaces "0

Re: [Tutor] pass arg to list

2019-07-18 Thread Steven D'Aprano
at the start of your script and see what is there. -- Steven ___ 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 Steven D'Aprano
arbage collected. ^1 Actually that's not too natural either. It is not usually a good idea to hold onto an open file when you aren't actively using it, as the number of open files is severely constrained on most systems. -- Steven

Re: [Tutor] Object references in Python

2019-07-16 Thread Steven D'Aprano
he string "blue" (by default). x.speak is a reference to the "speak" method of Parrot objects. Does this help? -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Multiprocessing with many input input parameters

2019-07-14 Thread Steven D'Aprano
ion is only called with a single argument. The rest is up to you. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Multiprocessing with many input input parameters

2019-07-12 Thread Steven D'Aprano
her syntactic precedence, such as a function call: func(9, 7)# Two integer arguments, not one tuple argument. func((9, 7)) # One tuple argument. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] collections and mappings

2019-06-21 Thread Steven D'Aprano
ve-driver.""", "Piano": """A parlor utensil for subduing the impenitent visitor. It is operated by depressing the keys of the machine and the spirits of the audience.""", "Quotation

Re: [Tutor] difference between array([1,0,1]) and array([[1,0,1]])

2019-06-21 Thread Steven D'Aprano
than 3x1? > Why this difference? Because that's how numpy arrays are designed to work. I'm not sure what sort of answer you expect. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Fwd: Re: Hii

2019-06-21 Thread Steven D'Aprano
p://dalelane.co.uk/blog/?p=1760 which I found here: https://www.google.com/search?q=python+count+keystrokes -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] word printing issue

2019-06-20 Thread Steven D'Aprano
which is the case. > Was thinking of using collection and still working on it. > If the above could be improved. I would be grateful. Without knowing what you are doing, it is hard to suggest improvements. "Dear cooking experts, I'm baking a cake and it turned out all wrong. What can I do to make it better? Thanks in advance." -- Steven ___ 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 Steven D'Aprano
il" can be written as a regular while loop, using a break: # do...until with test at the end while True: do_something() if test: break # "loop and a half" # https://users.cs.duke.edu/~ola/patterns/plopd/loops.html#loop-and-a-half while T

Re: [Tutor] Download audios & videos using web scraping from news website or facebook

2019-06-14 Thread Steven D'Aprano
t; download audios/videos using python code ? Please don't mistake "I don't know how to do this" for "this cannot be done". https://youtube-dl.org/ Scraping websites, especially scraping them for videos, can be *very* complex. -- Steven _

Re: [Tutor] would someone please explain this concept to me

2019-06-04 Thread Steven D'Aprano
nk) print(feeds) will print: {1: 'Goodbye'} {'a': {1: 'Goodbye'}, 'b': {1: 'Goodbye'}} (possibly the a and the b will be swapped around). -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] would someone please explain this concept to me

2019-06-04 Thread Steven D'Aprano
t; And it works. I don't see any difference between the replacement code and the original code. The code you show does exactly the same thing. > but why does it work? > > Why does that semi unlink all the variables? Semi-colon? It doesn't. You must have made other changes as well, semi-colons don't have any runtime effect. They are *purely* syntax to tell the parser to seperate multiple statements on one line. -- Steven ___ 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-06-04 Thread Steven D'Aprano
y works on Linux and other Unix systems with readline installed (which nearly all of them do). It won't work under Windows. But if you install the third-party library pyreadline, you *may* be able to use that instead: import pyreadline as readline and the rest might work. (I don't hav

Re: [Tutor] Case Insensitive Globing

2019-05-18 Thread Steven D'Aprano
On Sun, May 19, 2019 at 10:37:56AM +1000, Steven D'Aprano wrote: > That's not quite right -- case sensitivity of the OS isn't important, > case sensitivity of the *file system* is. And the standard file system > on Mac OS, HFS+, defaults to case-preserving but case-ins

Re: [Tutor] Case Insensitive Globing

2019-05-18 Thread Steven D'Aprano
d commands, including Python, follow suit. I don't think that is correct: https://apple.stackexchange.com/questions/22297/is-bash-in-osx-case-insensitive -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How arguments to the super() function works?

2019-05-18 Thread Steven D'Aprano
than plain old super(Class, self) in Python 2 or super() in Python 3 is considered rather advanced. -- Steven ___ 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 Steven D'Aprano
s no attribute 'command' That error message is completely correct: Popen objects don't have an attribute called "command". You are tring to print your own error message, referring to "proc.command" but there is no such thing. What are you trying to do? You need to find another way to do it. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

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

2019-04-29 Thread Steven D'Aprano
s.python.org/3/howto/descriptor.html Python has a few common descriptors built in: - ordinary methods - classmethod - staticmethod - property Apart from staticmethod, they're all pretty common in code. But writing your own custom descriptors is fairly rare.

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

2019-04-29 Thread Steven D'Aprano
general, you should treat all dunder (Double UNDERscore) methods as private to Python, and only implement those that you need. Don't use them for your own purposes. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or

Re: [Tutor] urlGET information

2019-04-28 Thread Steven D'Aprano
ent within the wheel that would provide more context? Wheels don't magically create documentation out of thin air. If the library isn't documented, where would it get the documentation from? -- Steven ___ Tutor maillist - Tutor@python.org To u

Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType

2019-04-26 Thread Steven D'Aprano
rhaps you are stuck in the moderator queue? -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType

2019-04-25 Thread Steven D'Aprano
def spam(self): ... self.count += 1 ... return ' '.join(['spam']*self.count) ... py> import sys py> sys.modules['__main__'].__class__ = Magic py> import __main__ py> __main__.spam 'spam' py> __main__.spam 'sp

Re: [Tutor] module import from a packager works inconsistent between REPL and command line

2019-04-25 Thread Steven D'Aprano
a good design for importing libraries doesn't always make a good design for scripts that you call directly from the command line, and visa versa, so the import system is a bit of a compromise between the two. -- Steven ___ Tutor maillist - Tuto

Re: [Tutor] str.replace error

2019-04-25 Thread Steven D'Aprano
"Something here? ~Basic P1~ but I don't know what" print("Before:", mystring) mystring = mystring.replace("Basic P1", "") print("After:", mystring) print(next(csvReader)) Hopefully that's enough to set you on t

Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType

2019-04-25 Thread Steven D'Aprano
why/when should we use this > technique, but the how. Can to share which documentation you are reading? I've been using Python since version 1.5, and I've never heard of this technique. Thanks. -- Steven ___ Tutor maillist - Tu

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

2019-04-23 Thread Steven D'Aprano
gt; obj.x Traceback (most recent call last): File "", line 1, in File "", line 5, in __getattribute__ [ previous line repeats 332 times ] RecursionError: maximum recursion depth exceeded while calling a Python object Normally, overriding __getattribute__ is consider

Re: [Tutor] Question on implmenting __getitem__ on custom classes

2019-04-23 Thread Steven D'Aprano
ult()): arg.append(1) return arg Now call: function() function() function() and see if you can work out what is happening. Hint: how many new lists are created? when are they created? -- Steven ___ Tutor maillist - Tutor@python.org To unsu

Re: [Tutor] Question on implmenting __getitem__ on custom classes

2019-04-23 Thread Steven D'Aprano
else: >     return self.list[key] The "isinstance" check is useless, because you do precisely the same thing in both branches.     def __getitem__(self, key): return self.list[key] will do exactly the same, and more efficiently. [1] Not actually a guarante

Re: [Tutor] Trouble with SUM()

2019-04-20 Thread Steven D'Aprano
AMT + AMT)) That's a good first attempt. Rather than set the price to float(sum(AMT + AMT)), which doesn't work, set the price to 0 before the loop starts. Then each time through the loop, set the price to price + AMT: price = price + AMT -- Steven _

Re: [Tutor] Mutable objects as dictionary keys: Accessing , Sorting and Using dictionary

2019-04-18 Thread Steven D'Aprano
if isinstance(other, MyClass): return self.name < other.name return NotImplemented But again, I'm not convinced that you need this class at all. Can you please show us the proc names you get, how you get them, and what you do with them? Using a wrapper class

Re: [Tutor] Questions about the deprecation of standard library modules

2019-04-02 Thread Steven D'Aprano
ot, too many people are still using it and so it can't be removed. On the other hand, its also not ususual for modules to be removed promptly. Usually its: - one or two releases silently marked as deprecation pending; - one or two releases marked depreciation (ac

Re: [Tutor] error message

2019-03-21 Thread Steven D'Aprano
notices* the problem, not where the problem *starts*. In this case, the problem is you are missing a space between the "def" keyword and the "__init__" method name. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe

Re: [Tutor] (no subject)

2019-03-16 Thread Steven D'Aprano
advice? Thank you. Yes -- read the error message. What does it say? (Reading, and understanding, error messages is probably the most important skill a programmer can have.) -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Python Regular Expressions (Re.sub) Function

2019-03-04 Thread Steven D'Aprano
Hi Edward, and welcome. Please remember that we're volunteers, doing this for free. Unless your problem is really interesting, you're not likely to get people volunteering to spend a long time slogging through multiple attachments, screenshots, at least five seperate attempts, etc. By the way,

Re: [Tutor] schedulers

2019-02-28 Thread Steven D'Aprano
ething running once a day :-) There's also the problem that you have to remember to launch your scheduler program every time you log in. Again, registering your backup program with the OS once means you don't have to think about it. -- Steven _

Re: [Tutor] schedulers

2019-02-28 Thread Steven D'Aprano
boots (what if the computer is off when the job is supposed to run?) etc. If for some reason you need to write your own scheduler, using a "busy loop" where you run a loop continually checking the time is not the right answer. (I don't know what the right answer is

Re: [Tutor] I flip a coin 1 million times what is the consecutive times it will come up head and come up tails

2019-02-27 Thread Steven D'Aprano
e: got 1 consecutive heads (1,) got 1 consecutive tails (0,) got 4 consecutive heads (1, 1, 1, 1) got 3 consecutive tails (0, 0, 0) got 1 consecutive heads (1,) got 1 consecutive tails (0,) got 7 consecutive heads (1, 1, 1, 1, 1, 1, 1) got 1 consecu

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

2019-02-26 Thread Steven D'Aprano
", line 1, in File "", line 2, in test UnboundLocalError: local variable 'count' referenced before assignment There's no point us trying to debug code you aren't actually running. Try again with the actual working code. It might help if you read this: http

Re: [Tutor] Proxy for Python?

2019-02-06 Thread Steven D'Aprano
entering a proxy, but *where* are you entering it and what are you doing with it? -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] ssl verification failed error

2019-01-24 Thread Steven D'Aprano
On Thu, Jan 24, 2019 at 03:03:28PM +1100, Riley Harris wrote: > When I try to install packages in python this error occurs. Please copy and paste (don't summarise or re-type from memory) the actual command you are running and the exact error message you receive. -- Steve

Re: [Tutor] Function not using updated variable?

2019-01-20 Thread Steven D'Aprano
Hi Ello, and welcome! On Mon, Jan 21, 2019 at 01:14:55AM +0100, Ello Solcraft wrote: > # currLocation doesn't use the updated variable. How do you know? I'm sorry, but it is impossible for me to tell what is going on here. There simply isn't enough information to understand your code. We don'

Re: [Tutor] Implementation of list comparison operators

2019-01-17 Thread Steven D'Aprano
On Thu, Jan 17, 2019 at 03:05:17PM -0600, David Rock wrote: > In [7]: nan == nan > Out[7]: False > > In [8]: a = 1.1 > > In [9]: a ==a > Out[9]: True > both a and nan are floats, so why does a == a work, but nan == nan > doesn’t? They both "work", because they both do what they are designed

Re: [Tutor] Fwd: Re: Doubt in Python

2019-01-17 Thread Steven D'Aprano
On Thu, Jan 17, 2019 at 09:57:03AM +, Alan Gauld via Tutor wrote: > The algorithm is probably described somewhere in the documentation > but my understanding is that it looks something like this(in pdeudo code): List, tuple and string comparisons are defined as lexicographical order: http://

Re: [Tutor] Debugging a sort error.

2019-01-13 Thread Steven D'Aprano
On Sun, Jan 13, 2019 at 01:16:10PM +1100, mhysnm1...@gmail.com wrote: > Issue, following error is generated after trying to sort a list of strings. > > description.sort() > TypeError: unorderable types: float() < str() That tells you that you don't have a list of strings. You have a list of str

Re: [Tutor] Best way to write this countdown code

2019-01-12 Thread Steven D'Aprano
On Sat, Jan 12, 2019 at 09:44:21AM -0600, Joseph Gulizia wrote: > Thanks in advance as I've gotten wordy. > > I want to integrate the following working code into a website: [...] Start with a simpler question: how would you integrate *any* Python code into a website? Few (i.e. no) browsers dire

Re: [Tutor] Doubt

2019-01-07 Thread Steven D'Aprano
On Mon, Jan 07, 2019 at 09:59:31PM +0530, Amit Yadav wrote: > How can simply typing > > print "hello world" > > work? > Like without including any header file or import statements how can it work. Why shouldn't it work? Python is not C and doesn't use header files. In Python, the interpreter k

Re: [Tutor] Python installtion

2019-01-07 Thread Steven D'Aprano
On Mon, Jan 07, 2019 at 03:36:01PM +0530, mousumi sahu wrote: > Dear Sir, > I am trying to install python 2.7.10 on HPC. Python 2.6 has already been > install on root. I do not have root authority. Please suggest me how can I > do this. What's HPC? If you don't have root permission, do you have p

Re: [Tutor] running a game server

2019-01-06 Thread Steven D'Aprano
On Sun, Jan 06, 2019 at 02:14:10PM +, nathan tech wrote: > My question is, is python really the way to go for game servers? *shrug* Do game servers have unique requirements that are different from (say) mailing list servers and other servers? That's not a rhetorical question. I don't know

Re: [Tutor] function question

2019-01-05 Thread Steven D'Aprano
Hello David, and welcome! On Sat, Jan 05, 2019 at 11:18:04AM -0500, David Lynch wrote: [...] > From what I've read about functions I should be able to define a function > with 2 variables? And then I can add all of my code into that function by > indenting it. So far so good! Here's an example

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

2019-01-02 Thread Steven D'Aprano
On Wed, Jan 02, 2019 at 08:39:53PM +0530, Asad wrote: > Hi All , > > Need advice on the following piece of code : Let me write it in a more "Pythonic" style: PATCH = r'\?/patch/\d{8}/\d{8}/admin/load.sql' APPLY = r'Starting\s+apply\s+for\s+patch\s+\d{8}/\d{8}' ERROR = r'set_metadata' tail = d

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

2018-12-30 Thread Steven D'Aprano
On Sun, Dec 30, 2018 at 11:07:19AM -0500, Avi Gross wrote: > Steve, > > I had the same thoughts and many more when I played with these ideas > last night. Pity that one of those thoughts wasn't "I shouldn't suggest a bad solution on a mailing list populated by beginners who won't recognise how

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

2018-12-30 Thread Steven D'Aprano
is explicit and right there in plain sight. This then allows us to make the submit_order() far more resiliant: if it is passed an invalid order, it can either fail fast, giving an obvious error, or at least skip the invalid order and notify the responsible people. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

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

2018-12-29 Thread Steven D'Aprano
On Sat, Dec 29, 2018 at 11:42:16AM +0530, Karthik Bhat wrote: > Hello, > > I have the following piece of code. In this, I wanted to make use > of the optional parameter given to 'a', i.e- '5', and not '1' > > def fun_varargs(a=5, *numbers, **dict): [...] > > fun_varargs(1,2,3,4,5,6,7,8,9

Re: [Tutor] decomposing a problem

2018-12-28 Thread Steven D'Aprano
On Fri, Dec 28, 2018 at 10:39:53PM -0500, Avi Gross wrote: > I will answer this question then head off on vacation. You wrote about 140 or more lines, but didn't come close to answering the question: how to randomly split data from a dictionary into training data and reserved data. -- Steve

Re: [Tutor] decomposing a problem

2018-12-28 Thread Steven D'Aprano
On Fri, Dec 28, 2018 at 03:34:19PM -0500, Avi Gross wrote: [...] > You replied to one of my points with this about a way to partition data: > > --- > The obvious solution: > > keys = list(mydict.keys()) > random.shuffle(keys) > index = len(keys)*3//4 > training_data = keys[:index] > reserved = k

Re: [Tutor] Interpreter pasting Question

2018-12-27 Thread Steven D'Aprano
On Fri, Dec 28, 2018 at 12:58:00AM -0500, Avi Gross wrote: [...] > Copying and pasting multiple lines into the interpreter fails in mysterious > ways, unless they are a logical single entity. > > Is there a way to change this behavior, or perhaps an editor/environment > that feeds multiple lines

Re: [Tutor] dangerous class neighborhood

2018-12-27 Thread Steven D'Aprano
On Thu, Dec 27, 2018 at 09:48:02PM -0500, Avi Gross wrote: > Sometimes when I post something I get back comments and evaluate them and > learn quite a bit. I then reply and debate every little point and it can > continue for a few rounds. I think you sent this to the wrong mailing list. The origin

Re: [Tutor] Re Module

2018-12-27 Thread Steven D'Aprano
On Thu, Dec 27, 2018 at 08:40:12PM +0530, Asad wrote: > Hi All , > > I trying find a solution for my script , I have two files : > > file1 - I need a search a error say x if the error matches > > Look for the same error x in other file 2 > > Here is the code : > I have 10 different pa

Re: [Tutor] decomposing a problem

2018-12-27 Thread Steven D'Aprano
On Wed, Dec 26, 2018 at 11:02:07AM -0500, Avi Gross wrote: > I often find that I try to make a main point ad people then focus on > something else, like an example. I can't speak for others, but for me, that could be because of a number of reasons: - I agree with what you say, but don't feel li

Re: [Tutor] decomposing a problem

2018-12-27 Thread Steven D'Aprano
On Thu, Dec 27, 2018 at 07:03:18PM +, Mark Lawrence wrote: > On 26/12/2018 00:00, Avi Gross wrote: > >[Long enough that some should neither read nor comment on.] > > > > PLEASE GO AWAY YOU ARE REALLY IRRITATING. People in glass houses... Mark, you're not the arbiter of who is allowed to post

Re: [Tutor] decomposing a problem

2018-12-25 Thread Steven D'Aprano
On Tue, Dec 25, 2018 at 11:56:21PM -0500, Avi Gross wrote: > I find that many people are fairly uncomfortable with abstraction and > tend to resist a pure top down approach by diving to any solutions > they may envision. https://blog.codinghorror.com/it-came-from-planet-architecture/ > As some

Re: [Tutor] decomposing a problem

2018-12-25 Thread Steven D'Aprano
On Tue, Dec 25, 2018 at 10:25:50PM -0500, Avi Gross wrote: > class chainable_list(list): > """Same as list but sort() can now be chained""" > def chainsort(this, *args, **kwargs): > this.sort(*args, **kwargs) > return this In Python, it is traditional to use "self" rather

Re: [Tutor] decomposing a problem

2018-12-25 Thread Steven D'Aprano
On Wed, Dec 26, 2018 at 01:06:04AM +, Alan Gauld via Tutor wrote: > In Smalltalk the default return value from > any method is self. In Python it is None. > > self allows chaining of methods, None does not. You might be interested in this simple recipe for retrofitting method chaining onto

Re: [Tutor] loop error

2018-12-20 Thread Steven D'Aprano
On Thu, Dec 20, 2018 at 10:47:44PM +0100, Aine Gormley wrote: > Hello, could somebody take a quick look at my code? I am unsure why I am > getting a loop error? That's hard to do if you don't show us the code :-) Please COPY AND PASTE (don't try to retype it from memory) the MINIMUM amount of c

Re: [Tutor] Python

2018-12-20 Thread Steven D'Aprano
On Thu, Dec 20, 2018 at 10:49:25AM -0500, Mary Sauerland wrote: > I want to get rid of words that are less than three characters > f1_name = "/Users/marysauerland/Documents/file1.txt" > #the opinions > f2_name = "/Users/marysauerland/Documents/file2.txt" > #the constitution Better than comments

[Tutor] Obfuscated Python [was Long Lines techniques]

2018-12-13 Thread Steven D'Aprano
On Thu, Dec 13, 2018 at 11:07:59PM -0500, Avi Gross wrote: > Python may claim to be straightforward but I can easily see ways > to fool people in python too with dunder methods or function closures or > decorators or ... Dunder methods shouldn't fool anyone. Each dunder method has a straightforw

Re: [Tutor] Long Lines techniques

2018-12-13 Thread Steven D'Aprano
On Thu, Dec 13, 2018 at 11:07:59PM -0500, Avi Gross wrote: [...] > There are cases where it may make sense to have a long like connected by AND > or OR given how python does short-circuiting while returning the last thing > or two it touched instead of an actual True/False. For example, you may wa

Re: [Tutor] Long Lines techniques

2018-12-13 Thread Steven D'Aprano
On Fri, Dec 14, 2018 at 01:03:55AM +, Alan Gauld via Tutor wrote: > I'd probably suggest > > stgs = ''.join([ > "long string", > "another string", > ... > "last string" > ]) That's certainly better than using the + operator, as that will be quite inefficient for large numbers of strings. Bu

Re: [Tutor] Long Lines techniques

2018-12-13 Thread Steven D'Aprano
On Thu, Dec 13, 2018 at 12:36:27PM -0500, Avi Gross wrote: > Simple question: > > When lines get long, what points does splitting them make sense and what > methods are preferred? Good question! First, some background: Long lines are a potential code smell: a possible sign of excessively ters

Re: [Tutor] Python script errors

2018-12-12 Thread Steven D'Aprano
On Wed, Dec 12, 2018 at 06:57:09AM -0600, Ravi Kumar wrote: > I know this occurs when the api response is nulls but how do I handle this? if response is None: handle None case else: handle non-None case -- Steve ___ Tutor maillist - Tutor@

Re: [Tutor] Python_About "Guess my number" program

2018-12-12 Thread Steven D'Aprano
Hi Dat, and welcome! On Wed, Dec 12, 2018 at 11:26:30AM +0600, Hoang Quoc Dat wrote: [...] > After a while, I went on and search on the internet and > find out 1 similar program but the coding logic is like: The computer keeps > guessing the middle number of the range and narrow down the range by

Re: [Tutor] Increase performance of the script

2018-12-12 Thread Steven D'Aprano
On Wed, Dec 12, 2018 at 12:52:09AM -0500, Avi Gross wrote: > Asad, > > I wonder if an import from __future__ happened, perhaps in the version of > collections you used. Later versions of 2.x allow optional use of the 3.x > style of print. The effect of __future__ imports, like any other import,

Re: [Tutor] Increase performance of the script

2018-12-11 Thread Steven D'Aprano
On Tue, Dec 11, 2018 at 09:07:58PM +0530, Asad wrote: > Hi All, > > I used your solution , however found a strange issue with deque : No you haven't. You found a *syntax error*, as the exception says: > >>> print 'Deque:', d > File "", line 1 > print 'Deque:', d >

Re: [Tutor] Increase performance of the script

2018-12-09 Thread Steven D'Aprano
On Sun, Dec 09, 2018 at 03:45:07PM +0530, Asad wrote: > Hi All , > > I have the following code to search for an error and prin the > solution . Please tidy your code before asking for help optimizing it. We're volunteers, not being paid to work on your problem, and your code is too ha

Re: [Tutor] Increase performance of the script

2018-12-09 Thread Steven D'Aprano
On Sun, Dec 09, 2018 at 03:45:07PM +0530, Asad wrote: > Hi All , > > I have the following code to search for an error and prin the > solution . > > /A/B/file1.log size may vary from 5MB -5 GB [...] > The problem I am facing in performance issue it takes some minutes to print > out the

[Tutor] Weird Unicode encode/decode errors in Python 2

2018-12-08 Thread Steven D'Aprano
This is not a request for help, but a demonstration of what can go wrong with text processing in Python 2. Following up on the "Special characters" thread, one of the design flaws of Python 2 is that byte strings and text strings offer BOTH decode and encode methods, even though only one is mea

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

2018-12-08 Thread Steven D'Aprano
On Sun, Dec 09, 2018 at 09:23:59AM +1100, Cameron Simpson wrote: > On 07Dec2018 21:20, Steven D'Aprano wrote: # Python 2 > >>>>txt = "abcπ" > > > >but it is a lie, because what we get isn't the string we typed, but the > >interpreter

Re: [Tutor] Regarding Python api script

2018-12-07 Thread Steven D'Aprano
On Fri, Dec 07, 2018 at 12:30:18PM -0500, Avi Gross wrote: > # > I have often seen something like this done with methods, such as to > # > emulate decorator functionality where a method is created in an > # > object with a name > # > and the very next method created has the same name with the

Re: [Tutor] Regarding Python api script

2018-12-07 Thread Steven D'Aprano
On Fri, Dec 07, 2018 at 05:59:22PM +, Alan Gauld via Tutor wrote: [...] > > ... In languages without garbage collection, reusing > > the same name, like "index" repeatedly might save some > > small amount of space. > > Garbage collection only helps if the variable loses > its assignment. If

Re: [Tutor] Regarding Python api script

2018-12-07 Thread Steven D'Aprano
On Thu, Dec 06, 2018 at 09:13:01PM -0500, Avi Gross wrote: > But so much code I see in python does not only reuse the same variable names > but in a confusing way. > > file = "some name" > file = open(file, "r") > file = some_wrapper(file) I agree this is confusing: you have the same name, "fil

Re: [Tutor] playing sound files in python

2018-12-07 Thread Steven D'Aprano
On Fri, Dec 07, 2018 at 02:17:55AM +, nathan tech wrote: > Hello all! > > My name is nate, and I am relatively new to this list, relatively being > just signed up. > > I have a question that you would think would be obvious, but alas I have > struggled to figure out. > > How do I play soun

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

2018-12-07 Thread Steven D'Aprano
On Fri, Dec 07, 2018 at 02:06:16PM +0530, Sunil Tech wrote: > Hi Alan, > > I am using Python 2.7.8 That is important information. Python 2 unfortunately predates Unicode, and when it was added some bad decisions were made. For example, we can write this in Python 2: >>> txt = "abcπ" but it is

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

2018-12-07 Thread Steven D'Aprano
On Fri, Dec 07, 2018 at 01:28:18PM +0530, Sunil Tech wrote: > Hi Tutor, > > I have a trouble with dealing with special characters in Python There are no special characters in Python. There are only Unicode characters. All characters are Unicode, including those which are also ASCII. Start her

Re: [Tutor] Regarding Python api script

2018-12-06 Thread Steven D'Aprano
On Thu, Dec 06, 2018 at 08:17:23AM -0600, Ravi Kumar wrote: > I know I am asking a lot Yes you are. Please read this: http://sscce.org/ It is written for Java programmers, but it applies equally to all languages, including Python. Think about how difficult a job you are giving us: we don't

Re: [Tutor] Borrowing restricted code

2018-12-06 Thread Steven D'Aprano
On Thu, Dec 06, 2018 at 10:41:37AM +, Alan Gauld via Tutor wrote: > On 06/12/2018 00:45, Steven D'Aprano wrote: > > > As for what is "not worth prosecuting", there are no copyright police > > who troll the internet looking for copied lines of code. Nobody

Re: [Tutor] Borrowing restricted code

2018-12-05 Thread Steven D'Aprano
On Wed, Dec 05, 2018 at 07:49:58PM +, Mark Lawrence wrote: > On 05/12/2018 16:22, Avi Gross wrote: > > [huge snip] > > Please take yourself to another forum, your ramblings have no place on > the *PYTHON TUTOR* mailing list. Steady on Mark, a lot of what Avi says is misinformed or close to

Re: [Tutor] Borrowing restricted code

2018-12-05 Thread Steven D'Aprano
On Wed, Dec 05, 2018 at 11:22:35AM -0500, Avi Gross wrote: > I am NOT advocating copying code. Not even "free" code. > > I am saying there may be times you want to package the code for special > purposes. "Packaging" the code IS copying the code. > Perhaps someone can enlighten me on a subtle

Re: [Tutor] Any 'graphical' ways of learning Python

2018-12-05 Thread Steven D'Aprano
On Wed, Dec 05, 2018 at 11:39:49AM +1100, Matthew Polack wrote: > Hi All, > > We're using Python with our Year 9 and 10 students to teach programming. Yay! And I see you're a fellow Aussie :-) > I've started with basic console programming...doing simple games like a > quiz game etc. > > Studen

  1   2   3   4   5   6   7   8   9   10   >