hunks lazily.
Cheers,
Cameron Simpson
_______
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
chunks(items, n):
... return zip_longest(*[iter(items)]*n)
...
>>> chunked = chunks("abcdefgh", 3)
>>> next(chunked)
('a', 'b', 'c')
>>> list(chunked)
[('d', 'e', 'f'), ('g', 'h', None)]
___
Tutor maillist - Tutor
ily so as to keep memory
drag at a minimum?
--- We not only inherit the Earth from our Ancestors, we borrow it from our
Children. Aspire to grace.
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.
ameron Simpson
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
ient code. Is nesting considered Pythonic?
Thanks!
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
ould not
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Thank you, Peter and Alan. Both very helpful. I was able to figure it out.
Cheers!
On Sat, Aug 17, 2019 at 5:45 AM Alan Gauld via Tutor
wrote:
> On 17/08/2019 00:46, C W wrote:
>
> The formatting seems messed up I'll try to straighten it out.
> I hope I get it right!
>
> Cav
>
>
> Micro-comment: a piece of code I'd hope to never see again:
>
> for x in range(len(map)):
> map[x].append(default_grid_format)
>
> this lazily produces a counter from the size of an iterable object
> (similar in concept to a generator), and then uses the cou
since you can just iterate the
object directly. Instead write it like this:
for m in map:
m.append(default_grid_format)
Micro-comment: you can use anything (well, anything "hashable") as the
key for a dict. So for:
key=str(x)+":"+str(y)
you can just do:
key = (x, y)
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
ht
low Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
_default_format():
return "whatever"
def show_cell(x, y):
print(f"x = {x}, y = {y}, format = {grid_formats[x,y]!r}")
grid_formats = defaultdict(get_default_format)
grid_formats[42, 42] = "this cell is special"
player_location = 3, 4
show_cell(*player_loca
r(player_x)+":"+str(player_y)
map[key]=default_grid_format
Is this an efficient method compared to 1?
Is it, code wise, sound logic?
I guess I'm just looking for a second opinion from experienced peoples.
thanks everyone.
Nathan
__
On Sun, Aug 18, 2019 at 12:35:52PM +0800, Thejal Ramesh wrote:
> Hi, i have a question regarding this question. I'm not quite sure what the
> question is asking.
Ask your tutor. We can help you with learning Python the programming
language, not graph theory.
https://en.wikipedia.or
mal for loop)
HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
_______
Tutor maillist - Tutor@python.org
T
list,3) returns [0]
. c) Calling popular(clayton list,0) returns [0,1,2,3,4].
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
n.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
oat],
b: Tuple[float, float, float]
) --> float: ...
Basically, use descriptive names for types rather than repeating their
definition.
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
kground.
Thanks a lot!
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
mments above.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
e two years ago I really meant it. If you can't be bothered have a look
at preshrunk tools like grep, or find someone to write the code for you.
> Thanks in advance.
You're welcome.
___
Tutor maillist - Tutor@python.org
To unsubscribe or change
@graniteweb.com
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
' object is not
callable'.
Assistance will be much appreciated.
Thanks in advance.
--
Stephen P. Molnar, Ph.D.Life is a fuzzy set
http://www.Molecular-Modeling.net Multivariate and stochastic
614.312.7528 (c)
Skype: smolnar1
_______
Tutor mail
that
> sends your data off to a web service and you get answers back.
>
> There are probably dozens more... this seems to be an area with a lot of
> reinvention going on.
>
> ___
> Tutor maillist - Tutor@python.org
> To unsubscribe
On 2019-08-13 15:49, tutor-requ...@python.org wrote:
> Send Tutor mailing list submissions to
> tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with sub
e and you get answers back.
There are probably dozens more... this seems to be an area with a lot of
reinvention going on.
_______
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Hi All,
I have many pdf invoices with different formats. I want to extract the line
items from these pdf files using python coding.
I would request you all to guide me how can i achieve this.
--
*Thanks & Regards,Nupur Jha*
___
Tutor mail
ghtly wrong code
just brings confusion.
Cheers,
Cameron Simpson
_______
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
s' 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
___
Tutor maillist - Tutor@python.org
To uns
a 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 hand.
Cheers,
Cameron Simps
ip, deflate, compress
Accept: */*
User-Agent: python-requests/2.2.1 CPython/2.7.6 Linux/3.13.0-170-generic
Body:
metadata=date=id
127.0.0.1 - - [13/Aug/2019 17:45:35] "POST / HTTP/1.1" 200 -
It looks like the data doesn't even get through.
___
on my own tutorial linked in my .sig below :-)
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
___
Tu
> but you're handing it "nums".
>
> Presently "nums" is a list of strings, thus the addition of the initial
> 0 to a str in the exception 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,
>
ed "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
ou know the difference between
an "int" and a "str[ing]"?
Given that both sum() and len() return numbers, what do you think is the
"str"? Might this refer back to the earlier suggestion that you need to
'see' the data being read?
--
Regards =dn
On 12/08/2019 19:35, Alan Gauld via Tutor wrote:
> To save some typing convert the?? int conversion loop into a function:
>
>
> def?? to_ints(strings):
> ?? num_copy = []
> ?? for num in nums:
> num_copy.append(float(num))
>
> ?? retur
quot;.
But I need the actual values, not just the name of the element. Any idea
how I can maintain this nested structure and retrieve the data within a
nested dictionary in an elegant way?
Constraints:
For simplicity, I omitted the actual payload which is also a nested
dictionary that goes two leve
def mean2(nums2):
>for num in nums2:
>_sum += nums2
> return _sum / len(nums2)
>
> def main():
>data = get_numbers()
>
>print("The mean of the first file is: ", mean)
>print("The mean of the second file is: ", mean2)
> main()
>
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Forwarding to tutorblist for info...
Forwarded Message
Subject:Re: [Tutor] HELP PLEASE
Date: Mon, 12 Aug 2019 19:34:48 +0100
From: Alan Gauld
Reply-To: alan.ga...@yahoo.co.uk
To: Marissa Russo
On 12/08/2019 19:17, Marissa Russo wrote:
> I fixed s
[str, str] Can be either a filename
or Base64 value.
What is the usage of "Union". I don't recall seeing anything like it
before.
it's type annotation. Search here:
https://docs.python.org/3/library/typing.html
OK, thanks.
Jim
___
Tuto
ther a filename
> or Base64 value.
>
> What is the usage of "Union". I don't recall seeing anything like it
> before.
it's type annotation. Search here:
https://docs.python.org/3/library/typing.html
_______
Tutor maillist - Tuto
of "Union". I don't recall seeing anything like it before.
Thanks, Jim
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
ou got comments
on other stuff already:
>>> def foo():
... return "string from foo()"
...
>>> print(foo)
>>> print(foo())
string from foo()
>>>
___
Tutor maillist - Tutor@python.org
To unsubscribe or
web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
for num in nums:
> _sum += num
> return _sum / len(nums)
>
> def mean2(nums2):
> for num in nums2:
> _sum += nums2
> return _sum / len(nums2)
>
> def main():
> data = get_numbers()
>
> print("The mean of the first f
his here:
m = mean(data[0])
m2 = mean2(data[1])
then print m and m2
>
> print("The mean of the first file is: ", mean)
> print("The mean of the second file is: ", mean2)
> main()
>
So, first, show the complete error message here.
> __
_sum += num
return _sum / len(nums)
def mean2(nums2):
for num in nums2:
_sum += nums2
return _sum / len(nums2)
def main():
data = get_numbers()
print("The mean of the first file is: ", mean)
print("The mean of the second file is: "
unate 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 (attributes)
are automatically in scope; in Python you have to access them through
the "cls" parame
organize your code; by writing
class Foo:
@staticmethod
def bar(...):
do stuff
instead of
def foo_bar(...):
do stuff
class Foo:
pass
you make the mental association between the class and the function a bit
stronger.
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
ons)))
return _dimensions
=8<--
The class method Foo.dimensions() is capable of accessing class members,
but Foo.dimensions1() cannot. What does the @staticmethod decorator really
add?
Thanks!
___
Tutor maillist - Tutor@pyth
ase quite a
lot more effort.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
_______
Tutor maillist - Tuto
data base
setattr(root.channel, name, SSE(name))
is what I was looking for, time to read up on attributes,
Thanks,
Ingo
_______
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
e argumentative; you have
to help us know enough before we can help you.
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
On 8/9/2019 7:39 AM, Alan Gauld via Tutor wrote:
On 09/08/2019 09:54, mhysnm1...@gmail.com wrote:
updates and insertions. I have multiple tables with the same structure with
differe
I agree 100% with Peter and Alan's responses.
--
Bob Gailer
to dynamically create instances assigned to root.channel attributes?
Assuming the latter:
name = # get from data base
setattr(root.channel, name, SSE(name))
--
Bob Gailer
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options
/weather/ will then become the emitter of the
weather event stream.
I'd like create the instances of SSE programmatically by pulling the
string 'weather', 'energy' etc. from a database.
Ingo
___
Tutor maillist - Tutor@python.org
To unsubscribe or change
n to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
_______
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https
unts
where name = account
# find records for account
records = select * from AccountEntries
where accountId = wanted_accountId
order by date desc
That design would greatly simplify adding accounts 3 to, say, 30.
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
than using a list of if tests?
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
his way (this is a snip from my
system, where the Python 3 came from homebrew, which is how I happen to
install it):
$ which python
/usr/bin/python# system version, you don't want this one
$ which python3
/usr/local/bin/python
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
.
Sean
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
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
Hello
I wanted to send you this email to ask if you would have someone that can solve
the problem I'm having with python.
I'm having issues with terminal on mac, is there someone that can help with
this?
Best regards,
Richard
___
Tutor maillist
graps the meaning. Every
time again.
If you use plural to indicate counts, what do you use for collections of
items?
--
"Honest criticism is hard to take, particularly from a relative, a
friend, an acquaintance, or a stranger."
-- Franklin P. Jones
Roel Schroeven
___
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
e database isn't being updated with the
new sub_category. All the database relationships are working when I manually
insert the data into the table via SQLIte3.
Any thoughts? Have I made myself clear enough?
Sean
___
Tutor maillist - Tutor@
“An expert is a man who has made all the mistakes which can be |
`\ made in a very narrow field.” —Niels Bohr |
_o__) |
Ben Finney
_______
Tutor maillist - Tutor@pyth
On 04/08/2019 09:15, Alan Gauld via Tutor wrote:
>>> Classes should never be named for their data but for their function.
> I was not suggesting that a class name should be a verb,
I think my biggest mistake here was the use of the word
"function" which, in a programming
lt in programs
that are procedural code disguised inside classes. And
that usually results in the worst of both worlds.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
NB am heading somewhat OT
NBB Python3+
On 3/08/19 12:38 PM, Alan Gauld via Tutor wrote:
On 03/08/2019 00:47, Malcolm Greene wrote:
Anyways, I'm looking for help coming up for the proper name for a class that
collects the following type of telemetry data
Classes should never be named
kr.com/photos/alangauldphotos
_______
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
ons of files, lines
> bytes. (i.e. arrays or tuples...)
> "___count" implies an integer.
> If the latter, I'd use "n_files", "n_lines" ... (possibly without the
> underscores if you find typing them a bother.)
> Comments?
I agree, plural nouns im
ot;files", "lines", "bytes" implies collections of files, lines
bytes. (i.e. arrays or tuples...)
"___count" implies an integer.
If the latter, I'd use "n_files", "n_lines" ... (possibly without the
underscores if you find typing them a bo
"bytes"... the plural form already tells you
it's a counter.
Opinions, we all have 'em :)
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Thanks for everyone's feedback. Some interesting thoughts including Alan's
"classes should never be named for their data but for their function" feedback.
I'm going to have to noodle on that one. Good stuff!
Malcolm
___
Tutor maillist
ather than the class name.
Sounds like a question for "an English Major". (Any Garrison Keillor
fans out there?)
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
//www.flickr.com/photos/alangauldphotos
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
escription.
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
s
JobStats or JobStatistics
JobTelemetry
None of these feel right and of course everyone on our team has a different
opinion.
Does this question ring any bells?
Thank you,
Malcolm
___
Tutor maillist - Tutor@python.org
To unsubscribe or change su
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
>')
func = cmd_dict.get(cmd)
--
Bob Gailer
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
ccomplish some of that with decorators, but not all.
_______
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Hi Alan,
thanks for that!
I realise I provided quite a lot of unnecessary info, but I've been
bitten a few times with the not providing enough so thought it best.
Thanks again for confirming my thoughts, that's very helpful.
Nate
On 02/08/2019 01:27, Alan Gauld via Tutor wrote:
> On 01
'.format(orig_func.__name__, t2))
return result
@logme
def hello(name, age):
print('I am {}, and I am {} years old'.format(name, age))
hello('Peter Parker', 20)
On Fri, Aug 2, 2019 at 12:14 AM Alan Gauld via Tutor
wrote:
> On 01/08/2019 10:11, Sinardy Xing wrote:
>
> &g
AM Alan Gauld via Tutor
wrote:
> On 01/08/2019 10:11, Sinardy Xing wrote:
>
> > start here---
> >
> > import logging
> >
> > ..snip...
>
>
> > from functools import wraps
> >
> > def logme(func_to_log):
> > import loggi
author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
> Thank you so much!
>
>
> What do you mean by "and change the directory before"?
>
> Python will start searching for 61.py in the *current* directory!
>
> --
> Regards =dn
> ___
> Tutor maillis
is blank. Please let me know what I'm doing wrong. Thank you so much!
What do you mean by "and change the directory before"?
Python will start searching for 61.py in the *current* directory!
--
Regards =dn
___
Tutor maillist - Tutor@
n 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
. Thank you so much!
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
> 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://mail.pytho
the line "Traceback..." to the end.
>
> Don't take a screen 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
> _
.
Kind regards,
Sithembewena
*Sent with Shift
<https://tryshift.com/?utm_source=SentWithShift_campaign=Sent%20with%20Shift%20Signature_medium=Email%20Signature_content=General%20Email%20Group>*
___
Tutor maillist - Tutor@python.org
To unsub
e):
print('Hello {}, I am {}'.format(name, age))
say_hello('Tonny', 8)
_______
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
kwargs))
> return func_to_log(*args, **kwargs)
>
> return wrapper
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
__
t 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://mail
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
alangauldphotos
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
1 - 100 of 74745 matches
Mail list logo