« first day (3947 days earlier)      last day (1005 days later) » 
01:00 - 18:0018:00 - 00:00

6:00 PM
cabbage
 
cbg
 
so, I was wondering: I'm trying to add N strings to a tuple but also joining them before that at the same time. Only managed to do the 'add N string to a tuple':
from itertools import islice

def grouper(n, iterable):
	it = iter(iterable)
	return iter(lambda: tuple(islice(it, n)), ())

# test data
test_data = """\
	1 some test
	2 some test
	3 some test
	4 some test
	5 some test
	6 some test
	7 some test
	8 some test
	9 some test
	10 some test"""

test_data = test_data.split("\n")

for i in grouper(3, test_data):
	print(i)
 
does that example need 20 lines here in chat?
 
ah, sorry. thought this would format it to be shorter
 
Shorter than what?
I don't see the "add N string to a tuple" part either
What are you trying to ask, again?
You mean group a list of strings in groups of N, and instead that you want to join each N-length tuple?
 
6:16 PM
@AndrasDeak if you try the for loop in the example, you would see it does add N string to a tuple :) but I'm stuck on actually making the N string joined together as a single string here
 
tuple(islice(it, n)) -> ''.join(islice(it, n))
or whatever separator you want
and you'll want an empty string as sentinel for iter
 
@NordineLotfi but that isn't what you've posted. There's an empty loop with grouper in it
 
hmm, the returning of iter(...) like that actually makes me unsure that my solution is enough
 
@roganjosh an empty loop? I'm afraid I don't understand...isn't the loop in the example above using print,and thus making it not empty? Sorry if I misunderstood :0
@AndrasDeak yeah, I actually tried that couple hours ago but sadly doesn't work...
 
I don't think I'm following this issue at all, sorry. I was wrong that you had an empty loop after your edit, but it just prints. What is the expected output of this?
 
6:21 PM
@NordineLotfi foolproof solution: map ''.join on your list of tuples
 
@roganjosh I only print to showcase the example itself :D I do have a use for this but I don't think it'll help knowing it here, so i omitted it to not make things more complicated
@AndrasDeak oh, I didn't try map yet :o Thanks, I'll try that
 
@NordineLotfi Then I don't know what you're asking. I can of course run your code, but if you don't show the expected output then I can't follow what the issue is
 
@roganjosh ah, my bad; I'll show a small output and wanted output in a second to better illustrate this
 
It may be that Andras has fully understood it, and it may be that others do too, and I'm the odd one out, but you've failed to pull me along on this journey
 
Please use shorter input data in your MCVEs, something like test_data = ['a', 'b', 'c', ...] would be much easier to work with
 
6:26 PM
yeah, good point
 
@Aran-Fey you're right. I usually don't use such long example but this time failed to shorten it. I'll keep that in mind :) Thanks
@roganjosh the code above output ('\t1 some test', '\t2 some test', '\t3 some test') instead of ('\t1 some test\n\t2 some test\n\t3 some test'). Here it actually divide the string in the test_data variable into N string, thus 3 + remainder in a tuple. But what I failed to do was to concatenate/join the said N string into a single one in their respective tuple.
 
So this?
def chunks(l, n):
    return ['\n'.join(l[i:i+n]) for i in range(0, len(l), n)]

# test data
test_data = """\
	1 some test
	2 some test
	3 some test
	4 some test
	5 some test
	6 some test
	7 some test
"""

test_data = test_data.split("\n")
print(chunks(test_data, 3))
 
6:44 PM
@roganjosh Yeah, it does seem to give the expected result :o Thanks. Here it output a list and use a list comprehension which I didn't do because: 1. I'm obliged to use tuple because of some function that need that, 2. I have this (mis?)conception that using a for loop/comprehension like this would maybe be slower than to use islice and iter like the previous example
of course I'm not saying a for loop is slow or anything, but I digress
 
Now it's all tuples:
def chunks(l, n):
    return [('\n'.join(l[i:i+n]),) for i in range(0, len(l), n)]
As to your second point, you aren't going to speed this up. I'm not sure what you think itertools is going to do here
 
@roganjosh Thanks a lot, this is perfect :0
@roganjosh yeah, I guess this was just a misconception then
 
This tuple business makes me think you're working with a database
 
@roganjosh hmm, to be honest with you, I need a tuple because I'm using it to send chunks of N lines of a file for multiprocessing. And as far as I'm aware, Pool.map only accept tuple? yeah
 
I don't think that's true, but I could be wrong
 
6:52 PM
I'm quite certain it eats all kinds of iterables, as any map should
 
@roganjosh yeah. I'm unsure either tbh
 
I also don't know how this chunking function gives something that lends itself to multiprocessing
Unless there's some intense calculation in NLTK or something... I don't get it
 
@AndrasDeak I meant that for the second argument but, let me show a very short example of what I mean:
p = multiprocessing.Pool(4)
chdir('testfirst')
h = 'testlast'
g = open(k, 'w')
with open(h, 'r') as f:
	for chunk in grouper(100, f, 'x'):
		results = p.map(process_chunk, chunk)
		for r in results:
			print(r, file=g)
here, process_chunk isn't important as it only work on the lines it receive
 
has anyone else faces speech recognition libraries like pyttsx3 and gttp not working on macOS??
 
It kinda is important. It's a trigram or something?
 
6:56 PM
the part I talked about earlier was the 'chunk' part, which is a tuple I think
 
good ol devil's advocate here: did you even need multiprocessing in the first place?
 
@roganjosh it isn't anything fancy I assure you :) It just work on the input string and output the result is all
@ParitoshSingh ah yes, I knew someone would say that...that's also why I said previously 'to not make things more complicated'
to tell you the truth: I don't know :0 but that's why I want to know by trying
 
i don't want you to give me code that shows the complex code, i just want you to...yep had a feeling
 
In the first few years of using python, I couldn't understand why anyone wouldn't use multiprocessing. I can honestly say now that I don't remember the last time I used it
 
6:58 PM
remember, time things first. you will very often be surprised.
 
@ParitoshSingh I do that all the time :) fine advice indeed
I use line_profiler, Cprofile and very recently, trace too...so I think I'm not too bad on that point
 
yeah, multi <threading/processing/some other newfangled thing> is not a silver bullet, and often you don't even need the performance gains in the first place.
 
What is line_profiler telling you?
 
did you run those on this current task with non multi-processing to get a baseline? and compared it against the multi processing code?
 
@roganjosh it work line by line afaik, although the requirement is that it technically only work on function, but still useful
 
7:01 PM
I know how it works. I'm asking you what it's telling you about your code
 
@NordineLotfi what does that code block tell me?
In [2]: from multiprocessing import Pool
   ...: p = Pool(4)
   ...:
   ...: print(p.map(str.upper, 'asdf'))
['A', 'S', 'D', 'F']
 
Alright @roganjosh, I'll send you an email later today or tomorrow. :)
 
THIS ^ code block tells me that strings work too. And I bet lists do too.
In [4]: In [2]: print(p.map(str.upper, iter('asdf')))
['A', 'S', 'D', 'F']
 
@lupus I don't check my website mail any more so you'll have to ping me when you do
 
THIS ^ tells me that string iterators work too
 
7:03 PM
are you a whatsapp user?
 
As of today, literally, no
It kept telling me it was out of date. I never use it, so I binned it
 
@AndrasDeak that is peculiar...I tried to use it with a variable and other things beside tuple but I guess I did it wrong somehow. Thank you for the clarification and example :)
 
e-mail then and I'll ping you. or you tell me a better way :)
 
@NordineLotfi I mean the simplest solution, for you, would be to read the docs
 
brb gotta reboot
 
7:05 PM
@AndrasDeak I did do that...but I admit I didn't read it all so you got a point still
 
you only need to read the part that tells you what the second argument has to be
 
right
 
7:30 PM
@AndrasDeak you're right, found the relevant doc :0 Thanks
 
@lupus my other laptop is in an update cycle. Just email me at j.pilkington@hotmail.com.
I cba keeping that one secret when people keep signing me up to weird mailing lists, or I get receipts for buying women's underwear, or asked to beat a church cross with a chain to give it a "weathered" look, or getting invited to a stag do in Vegas, or everyone's credit reports
 
Did you make it to Vegas?
 
I didn't. I also didn't get a gift in the super-secret-santa that I found myself in with people I've never met :'(
 
@roganjosh that's what I call varied spam :o usually they are less varied per email but I guess I was only taking into account my own experience hmm
 
@roganjosh guaranteed secret
 
7:45 PM
@NordineLotfi it's actually really bad. I tracked one of the recipients down on facebook. She lives in Canada; I got her credit report, her work documents and a mortgage application. She should really sue the companies involved but meh, that's up to her
That's autocorrect for you. .ca becomes .com
And now you've broken just about every data privacy law going
 
what is the naming convention for a virtual environment for a specific project? project_env?
 
I just call them env
You don't distribute them with your package anyway (you should exclude them in .gitignore) so it doesn't really matter
 
Doesn't really matter, since you're the only user of that venv. Go nuts if you want
 
@roganjosh wow. Yeah, i see what you mean...I guess her email was leaked because of some sites she used :/ I don't think this ever happened to me yet unless I'm unaware of it
 
Her email wasn't leaked. It just gets auto-corrected to my email
 
7:51 PM
@roganjosh oh, gotcha
 
is it normal? relative path begins with ".." instead of "."? then I spotted a typo in some tutorial
like if I want to use a file in my project folder ..\my_file
 
@SAJW I think it's normal yes. that's the kind of syntax used in linux iirc
 
@roganjosh honestly it's hotmail's fault for not reserving accounts across TLDs
 
.. is for the upper directory starting from your current one, so '/root/banana' -> '/root'. ./ is essentially similar here: . -> current directory, and / is for specifying the current directory/file
 
And ./thing is necessary if you want to run a script in the current directory, as a safety measure
 
7:57 PM
that too yeah
you can also do it for a directory without file iirc but you don't see it often
 
Not sure what you mean, but you can add as many no-op ./ parts into your path as you'd like (as long as the line length fits in your shell)
 
@AndrasDeak I meant that you can do something like cd ./directory or program ./directory :)
 
OK, that was my suspicion. See my previous message, then.
 
oh, yeah I see what you meant
 
mmh, so I want to load a .txt file (words seprated by newlines) into an array, such that the array looks like ['dog', 'cat', 'house', 'boat'], do I need numpy and earthpy for this or is there another way?
 
8:01 PM
@SAJW 1. numpy won't do that for you, 2. do you mean an array, or a list?
"Array" has at least 3 non-list meanings in python.
 
i will check out the definitions brb
 
OK
It won't be easy though because most sources online use it wrong (because, you know, most sources online are crap).
 
Why are you talking about earthpy here? Your example doesn't make any sense to me in that context
 
@roganjosh based on their earlier message, I'm guessing they mentioned earthpy because it's related to a tutorial they aw for something they wanted to do...or at least that's the impression I had
 
Ok. I'd rather they answered that themself, though
 
8:07 PM
ok, so I basicly found a bad solution, happens :D
 
If you just need to read lines into a list, google exactly that
 
does anyone here have any recommendation for a codebase/module that support huge files/can parse huge files? Just curious
only one I know is bigread but it seems to be discontinued
 
not having to declare types of variables seems nice
ok it works, but funny hehe: ['dog\n', 'house\n', 'cat\n', 'boat']
will figure that one out, thanks :)
sweet it works now :)
 
@NordineLotfi what is "huge" and what is the format?
 
@roganjosh hmm raw txt file? huge is relative here, 1gb-up to 100gb etc
I'm simply curious here is all
 
8:22 PM
If it's \n separated lines then you can just iterate the file object you get from open()
You can use dask potentially, if you need it in a dataframe structure
 
is it acceptable to "import Tkinter as tk"(for example) or does that cause confusion?
 
it doesn't cause confusion
 
@roganjosh That's something I didn't know. Thanks
 
Aliasing imports is common e.g. import numpy as np
It's certainly better than most resources on TKinter that show import *. I don't know why it's so common with that library
 
@roganjosh I noticed the same thing too on existing codebase. I'm guessing they were trying different things with the myriad of sub function/class on their editor/repl and forgot/didn'tcare about making it more streamlined/specific
I know I do that sometimes under ipython
 
8:29 PM
All the tutorials use import * too. It's just poor effort
 
yeah
talking about this, is there even a difference between doing from module import * and import module? afaik there isn't right?
 
Best run to the shops. rbrb a bit :)
 
take care!
 
@NordineLotfi yes, a massive difference. The former will inject all the functions into the namespace
Anyway, I have to go for a bit. The shops don't respect a need to explain python imports :P
 
haha, yeah, that would be a fun excuse to use :D
 
8:34 PM
so it's the python equivalent of using namespace std
?
 
8:58 PM
I don't know what you're asking because I don't know what you're referring to
I can't say it's the "python equivalent" if I don't know what we're comparing to
 
@NordineLotfi try doing array after import numpy
 
@roganjosh from module import *
 
That wasn't what I asked
 
both "from module import *" and "using namespace std" (c++) seem to save typing work, but are bad to use?
and lots of tutorials use those
 
sounds reasonable
 
9:08 PM
I can't comment on the C++ case, but yes it's bad in python
 
using namespace std lets you just use a name without explicitly specifying std::name. So yeah.
Although there's a chance that the compiler screams if there's a name clash
and honestly if a name is hidden among a dozen #include-s then it's barely better
 
but if it doesn't scream and the program does something not supposed to do, you just sit there with "???"
 
I was talking about C++, to be clear. Python's compiler or any other part has no issue with names shadowing one another.
 
ah ok
why is it still bad in python then? does it bloat the program unnecessary?
 
do import this in python and read what you see, then we'll continue
 
9:16 PM
I did it, so sometimes it can be good but often it isn't. I guess that's the intention of the text?
 
no
The Zen of Python is a half-serious collection of wisdoms that roughly specify what good python code is like.
The last one is key. Or at least relevant here.
> Namespaces are one honking great idea -- let's do more of those!
The problem with star imports is twofold: one is that dumping every name from a large module can indeed bloat your global namespace, as you said. But more importantly, it makes very hard to read and debug code when you can't instantly see where the name came from. And finally, multiple star imports can have name clashes, and that's not better than an error, it's far worse: you won't even notice until the object behaves differently from what you expect.
The sane rule of thumb is to avoid star imports altogether. The price is that when you need a lot of names from a module, you have to import each one explicitly, which can make the imports quite verbose. This is probably the reason why GUI libraries often lead to star imports: there are usually many names to import, and people are lazy.
So the alternative is to keep the namespace: import numpy as np and then use np.whatever each time you need it. This is the idiomatic use of numpy, for instance.
@AndrasDeak for certain values of two
@NordineLotfi what do you mean?
 
@AndrasDeak ah, nvm. Had to click to verify context since I thought you were answering another earlier comment I did
 
but you can do something like this I remember: from module import this, that. at least in pybricks that worked
 
@SAJW that's the first case I mentioned: having to list everything you want to import
 
9:26 PM
but at least you don't have to write from module import for everything you want from that module, just once i mean
 
@AndrasDeak but isn't just using import module also importing everything or I'm I misunderstanding something?
 
so unless it's like 100 functions I'm ok with it personally
 
@NordineLotfi clearly you didn't do what I told you to
29 mins ago, by Andras Deak
@NordineLotfi try doing array after import numpy
I never understand these confusions when you can just open up python and try for yourself
 
@AndrasDeak I'm using a phone right now, and also don't have numpy installed locally so :)
 
if you don't have numpy, you can do the same with ceil and import math
 
9:30 PM
oh
 
It shouldn't be "oh". Your mental model is "'import thing' binds every name of 'thing' into the current namespace". Any module with names in it should prove or disprove that.
 
I see
 
Since you're on mobile: doing import thing executes whatever is in thing, and binds the name thing (and only the name thing) in the current namespace.
Otherwise, yes, star imports would be superfluous.
If you think names can pop out of nowhere in python, you have to seriously readjust your mental model. Python is mostly sane in this regard.
 
@AndrasDeak ah, so essentially: star import -> pollute namespaces with more than just thing, import thing bind only thing. Feel free to correct me if I'm wrong :)
 
You're wrong, because of all things, a star import won't bind the name thing
they are pretty much disjoint
 
9:42 PM
@AndrasDeak so you mean...it will bind everything except thing?
 
yes
 
you don't need thing once you pull in everything inside into the current namespace
 
I think I got it now
@AndrasDeak Thanks for your explanation :D
 
import thing is "please put that box on the countertop". Then thing.foo is "use foo from the box". from thing import foo is "go over to the box and pick out foo". from thing import * is "just dump that whole box here, and throw the box away"
 
9:56 PM
So module.function() is preferred over function() in big projects, that's what I could gather. (assuming you make import module/from module import function)
Because module.function is easier to read which function from where the coder means.
and yet even better is "import module as md" and write md.function then
 
10:14 PM
Cbg!
Well, how do I plot the hours on the X axis, in the format like "15:00", based only on the size of the number of points to be plotted (using the len function on the y axis array)? In this case, I have 9000 points to be plotted, that's 15 minutes of points, 1 point every 0.00166666666 minute (15/9000). I have the following information: the start time (example, "17:45"), and end time (example, "18:00").
 
@SAJW from module import function is also fine, because if you search the code for the first occurence of function you'll see that it comes from `module.
 
So if I want word_to_guess= random word, it is irrelevant whether I use numpys rng or random.random? It's for a hangman game, so I doubt I need true rng.
 
@SAJW they are equally true. If you're not otherwise using numpy, forget about numpy.
 
@AndrasDeak ah ok, got it!
 
And by "equally true" I mean neither are true.
@Marco I'm not entirely clear on what you're asking, but as far as I know matplotlib only supports datetimes, and not times. So you might have to construct datetimes with a dummy day, and then use a matplotlib.dates.DateFormatter potentially with a matplotlib.dates.MinuteLocator or similar.
 
10:34 PM
Mmh, I thought about list limits via available RAM. I want my list to have like 300,000 English words. Do I need to worry about splitting the tasks into smaller ones to avoid memory limits? Like I could split the file into 10. Then roll a 10-dice and work only with 30,000 words.
 
300_000-length lists with a single word inside sound like no problem at all
 
Ok!
 
>>> x = ['potato' for _ in range(300_000)]
>>> (sys.getsizeof(x) + sum(sys.getsizeof(val) for val in x)) / 1024**2
18.21666717529297
that's about 18 megabytes for a 300_000-length list of potatoes
 
@AndrasDeak ok, thanks, I am trying to figure out how to do it.
 
about 16 MB for the strings, and 2.5 MB for the list itself
27 MB total if it's a list of 'pőtátő'
 
10:42 PM
do I need to intialize a seed per time to get a better rng? I use the module "random" with random_integer=random.randint(0, len(words)-1)
 
if you touch the seed it will only get worse
And if you're writing a hangman game, do you really have to worry about the quality of the PRNG?
 
well it should be random "enough" ;)
 
Have you looked at the docs of random.seed?
 
ouch, the first sentence answers my question
 
@AndrasDeak Another example (this is very simple): I have a Y-axis array with 10 elements. I know this data starts at 21:00. I want to plot hours and minutes on the X-axis. My data always has 15 minutes of data. So in this case, there will be one point every 10/15 minutes = 1.5 minutes. The first point on the X-axis will be 21:00 and the last will be 21:15.
 
10:47 PM
@Marco there are libraries that can do dateranges. But you can just use a starting datetime and use a timedelta with the appropriate delta.
But your description is buggy, it's not "one point every 10-15 minutes".
 
I corrected it, it was a division, 10/15
 
ah, yes
 
It ended up being written wrong
Sorry
@AndrasDeak Hmm... what would be the easiest way?
 
So I'd do something like start = datetime.datetime(1970, 1, 1, 21); interval = datetime.timedelta(minutes=15)/len(y); x = [start + interval*i for i in range(len(y))]. Something along those lines. But beware that I'm not much of a datetime user.
 
It looks great, thanks... start = "21:00"? Or something similar.
Wow, sorry...
I just forgot to copy a part here in the code.
 
11:01 PM
Perhaps it's better form to use datetime.time here, and only add fake dates for plotting
 
It worked perfectly!! Just a little thing, the day is showing up in front of each time, how do I remove it?
Like "25 17:45", "25 17:50", and so on...
@AndrasDeak I think it already worked, maybe I don't need it. Only this last adjustment that I mentioned is necessary.
 
@Marco Read what I wrote when you asked this earlier
 
Okay, maybe it would change to start = datetime.time(21:00)?
 
Good luck
 
11:40 PM
Ok, so I have now a window that updates its content, but I only want to read one word at a time, not the previous words, how do I do that? and if I'm making something wrong please say. Destroy just kills the window, which is not what I want :( pastebin.com/5wx5z817
also stating everytime how I want to have the words formatted seems superfluous
 
11:58 PM
@AndrasDeak I certainly didn't do it in the simplest and fastest way, but I managed to solve it... But you did the hard work. Thank you very much!!
 
01:00 - 18:0018:00 - 00:00

« first day (3947 days earlier)      last day (1005 days later) »