« first day (1649 days earlier)      last day (3299 days later) » 

12:05 AM
Is there anyway to add data to the start of a dictionary?
 
dictionaries have no order
ergo no
or rather "Dictionaries are an unordered mapping by definition"
 
I see, thank you.
 
@HarryBeasant why do you want to add something to the "beginning" of a dict?
you can do something like OrderedDict(reversed(sorted(denominations.items(), key=lambda t: t[0])))
 
there is an ordereddict and a named tuple ... that are kind of like dictionaries ... but with order
 
Had some currencies and wanted to add the base currency at the top
 
12:14 AM
hehe....and that's why I name the dict denominations :)
 
but I have added it inside the top "layer" or w/e its called
 
you mean it is defined first when you are defining the dictionary?
 
Well say I had dict['base'] = "USD"
then dict['rates']['GBP'] = "1.5101"
I wanted it in rates at the top
but its better outside
 
not sure I understand you but in that case why not use a list? (for the rates->GBP key)
@HarryBeasant might be a better idea to write up a good question and post it. As either I don't understand your question or your making a, fairly standard, mistake about dictionary use
 
 
3 hours later…
3:26 AM
Cbg
 
cbg
 
4:05 AM
cbg
 
4:48 AM
cbg means ?
 
5:54 AM
Hey up
 
banana
 
6:11 AM
Cabbage :-)
@davidism Same to same :-)
Wait, can we say who we voted in democracy? O_O
 
Why wouldn't you be able to?
 
My parents told me to not to even tell them who I voted.
 
6:27 AM
Eh. Of course you can tell people who you voted for.
 
Hmmm, probably they are worried about the bad politicians. Thanks man :-)
 
6:45 AM
good morning :)
 
cabbage @StephanKetterer
 
as per recommendation from here, i took 2.5 days and finished the code academy python tutorial
 
11 hours ago, by Robert Grant
@MartijnPieters time to replace your black clothes with celebratory blue? :)
Oh wow, sorry
That was a weird sequence of events
Cbg
 
can somebody tell me the difference between reader()and DictReader() i have a huge .csv file i have to work with
 
how to execute a statement automatically (say import sys; print(sys.path) ) just before running actual python script without editing script?
 
6:57 AM
@StephanKetterer dictreader yields dictionaries, reader yields lists
the former requires that the first line is headers; the latter does not care
 
ok that is a good starting point . thank you !
 
@ChillarAnand there are certain modules that are being executed before each script
site.py and
then sitecustomize.py and usercustomize.py
though you'd need to edit that script.
 
@AnttiHaapala can't we do it without editing script?
 
@AnttiHaapala my file seems to have a header file, with what i can assume are the keys for the dictionary then if i read it with DictReader
hmm shouldn't i be able then to print out something like dictname['keyname']
 
@ChillarAnand I guess you could specify PYTHONPATH that links to a directory with usercustomize.py that you wrote
works
@ChillarAnand so write a file usercustomize.py in your current directory with the contents as you proposed above
then run the actual script as PYTHONPATH=. python theactualprogram.py
 
7:18 AM
Cbg :)
 
Just realised this isn't working because isidigit doesn't detect decimal points
 
Herpaderp
 
if i have from a dictionary all strings, and i have to find out which entries are integers and which ones are floats
maybe look if there is a "." in the string and then combine it with a %1==0.0
 
7:48 AM
The positive integers match el.isdigit(), and the negative integers match el[0] == '-' and el[1:].isdigit() :)
@Ffisegydd wotcher
 
How's it going?
 
8:06 AM
Spent an embarrassing amount of time and lines of code on a codeeval problem last night
 
@RobertGrant My problem is, the values are all of type string, now some of them are integer and some are floats in reality
sitting on the programming assignment that should take like 1 hour for 2 weeks now
 
Cabbage!
 
@StephanKetterer that stuff shouldn't add 10 days :)
 
i am doing an udacitycourse and i think seriously about quitting.. since for 2 weeks i cannot move 1 inch forward
 
8:21 AM
It's annoying, but I just wrote a method to check if the string's a float. It's only because all my input is passed in as strings
 
i do every tutorial i can find
i have a .csv file.. they made it so big that it hardly runs on my computer
i should go through predefined columns and find out the occuring datatypes, put them in a set and write it in a dict with the column name
 
The size of the csv shouldn't matter, as you can iterate through it only loading one line at a time
 
but doesn't it take my computer longer to do it then if there are more lines?
 
cabbage
 
Yes
But it shouldn't "hardly run"
 
8:26 AM
last time it took 350 seconds
in sublime
or it just crashed
 
That sounds like a memory issue, because you're probably loading it all into memory first
 
i have no idea, maybe programming is too hard for me after all
 
"i have no idea, maybe programming is too hard for me after all" : Don't be down hearted. Usually the first few mistakes are misunderstandings about how things work / what the intention was and you won't make them again.
 
cbg @antii
 
8:33 AM
@JRichardSnape I will call @MartijnPieters here to exercise his mod powers
 
For instance - what Robert is saying here is that it sounds as though you might have loaded the huge CSV file into memory before processing it, rather than processing it one line at a time. Two different strategies - often (usually) the latter is preferred and especially when using big files / datasets.
 
Argh - now that's a wrongly spelt name and 2 mismatched brackets. I'm going to be (rightly) thrown out of here. My deepest apologies @AnttiHaapala - from Rcchard ;)
 
yeah, if it crashes or computer slows down it is because you're storing more and more data in the RAM
:D
apologies accepted :d
 
i am just a beginner
i am sure i make a ton of stupid mistakes
 
8:36 AM
Sure - everyone does (not even just beginners...)
 
just.. came here a couple of days ago.. thought i could solve it.. was recommended the codeacamedy tutorial (13 hours of material) and i really understood that and did every assignment.. back to my problem and again .. nothing :)
 
You'll make fewer as you learn.
 
this is what i have
FIELDS is a list with the key words i should examine
 
@StephanKetterer you're using pastebin, which means you have more of a capacity to learn than some people who come in here :)
 
8:39 AM
For instance - yesterday I spent quite a few hours tinkering with a graph I was making. Isolated the line that was failing, worked out a solution. Came on here talked about it, within 1 minute two people had said "ah yeah - that problem - here's a solution", both of which were more elegant than mine
That's learning
 
yeah, but you have to come to that point, where you can isolate it and work on it
 
(and I didn't use pastebin) ;)
 
i mean i pay them.. and all they do is give me super smug answers honestly
 
Pay who?
 
i do this udacity course, and i write in their forums.. they never tell me how to improve it or give me a link to a tutorial or something ... all i ever get is " think about...."
 
8:45 AM
How big is the file you're trying to load?
 
38.4mb as a .csv file, is that understandable or how do i measure it ?
 
You beat me to the exact same question
 
That's what I was after, yeah
Have you googled loading a csv file in python?
 
yes, and i think that in my pastebin works
atleast it gives a ton of entries
the file is too large for me to inspect it visually
 
Oh sorry, I can't access pastebin at work, so I'm maybe asking questions your code answers :)
 
8:47 AM
the problem with DictReader is,
i found out.. all i get is type string
so now, when they want me to find the type of the entries ( the real types).. i have to write a function that does that
this is what i have till now
will just paste it in here
so you can read
def get_the_type(value):
if value== "NULL" or value=="":
return(type(None))
elif (value[0]=="{"):
return (type([]))
else:
return(type("dasd"))
 
The stuff in your pastebin looks like a reasonable approach. I have a 74MB csv sitting here - and will try it out (I'm no guru on how the csv reader code within the python modules works under the hood
 
Okay
 
BTW - edit your post - select the code and press Ctrl-K - it formats it as code (HT Martijn Pieters)
 
It seems as though you're almost there; just got to figure out why the first two if conditions aren't matching
E.g. "the data never matches those" would be a possible reason
 
 def get_the_type(value):
	if value== "NULL" or value=="":
		return(type(None))
	elif (value[0]=="{"):
		return (type([]))
	else:
		return(type("dasd"))
 
8:52 AM
Add print("Processing value " + value) to the start of the function
 
Robert, the hard part is still missing ( actually a lot of them)
and that is
all the integer and floats
 
That'll be fine, don't worry about it
As long as the mechanism works
Maybe make a copy of your csv, and cut it down to the first few lines, so it's quicker to test with
 
the print is just for me to observe ?
 
Yes
Just for while you're coding; take it out when it works
 
i mean i can test this function without the csv file, and just giving it manual input i thought
 
8:54 AM
commute cbg
 
giggle you're all blue...
 
You can, but you'll probably want to test it with a small file, so you know exactly what you're getting passed into the get_the_type function from the file
Dabadedabadoo
 
see, my first understanding problems
 
DabaDEEba
 
dont i already know that i all i ever get passed is strings ?
 
8:55 AM
@AnttiHaapala did someone get my name wrong again? aims the account suspension tool
@RobertGrant like that hasn't been going through my head all night.
 
@MartijnPieters Eeek ;D
 
@StephanKetterer it's just worth eliminating any assumptions
 
i had the type outputted as well
so i know its all strings
gonna give myself till 1.6. to solve that problem lol
the number.. i am thinking for hours how to convert and maybe use modulo to find out what it is
 
Just test if you can convert to float
 
@StephanKetterer One thing I do notice in your pastebin example. The second argument (variable in brackets) that you pass into your function is named lower case fields, but you use uppercase FIELDS in your loop. These are not referring to the same variable.
 
9:00 AM
def str_is_float(value):
    try:
        test = float(value)
    except ValueError:
        return False
return True
#Untested and written by a beginner
 
so you suggest writing a third function ?
this is really melting my brain, since your function in the current form would not help it either, because it would never yield an integer , since i could convert all strings that are really integers into floats
 
Very good :)
So test for int first, with a different function, then if that fails test for float
 
ok. i mean i could just clone that one you wrote with int
that would up the count to 4 functions
 
I wouldn't worry about the number of functions, unless that's a constraint
 
ok.. i was just worried it behaved like an onion and i need more and more functions
 
9:04 AM
Well you might need a few, but that's a useful thing to experience, because at some point you'll learn about code organisation, and if you've only had one function, then you won't get why it's useful
And as a more general point: one huge function bad. Two (or more) useful, reusable functions better.
 
i assume i have to put the testing for int before testing for float, otherwise i would always get floats
 
i am really not lazy and want just the solution on a plate.. just hard starting out i guess
 
Bleh my voicemail just randomly stopped working.
 
@StephanKetterer It's obvious you're not lazy, or you wouldn't have bothered finding this place and having genuine code attempts to show.
 
9:09 AM
@StephanKetterer yeah I'm a good person to talk to because I only know slightly more than you, and won't be able to hand you an answer :)
 
Is it possible that in your suggestion, the last return statement has to be indented?
because it shows as on the same line as "def" and i think that cannot be
 
@StephanKetterer yes :)
Should be same indent as try:
 
yeah i figured, just thought gonna ask it before doing it on my own
 
@StephanKetterer yes - the return should have been indented. Also - I can verify that your file input function works find on a huge file - with a 78MB csv, it never uses more than 3MB memory. So your problem is not there (barring the fields vs FIELDS issue I mentioned above.
 
Unless your file is one enormous line :)
 
9:13 AM
@JRichardSnape FIELDS is defined as a list above it with the keys i am interested
 
I'll leave you and @RobertGrant to discuss the conversion of strings to ints / floats where appropriate, but the approach he's suggesting seems reasonable to me.
@StephanKetterer Sure - and that's why it works. But, say you want to re-use your function with a different fields list. You don't want to rely on a global variable called FIELDS - it's bad practice. You're already passing in an argument for that. I'll demo
(names not important - I've just changed them to make the difference clear.
 
i even understand what you are saying :)
and thank you
 
Good. In that case - no need to prep a demo :)
 
the way i use it,, i cannot just take the function i wrote and use it in an universal way whenever something like that comes up
 
if you call your function with audit_file('your_file.csv', FIELDS) but then use fields in the function - you can then call the function with audit_file('my_other_file.csv', my_other_fields) when you want to reuse it
 
9:17 AM
@RobertGrant this is how it looks like, does not give me errors running , but does not find the right filetype either pastebin.com/xbJGgvdm
forget it, it seems the work, no idea what i did there to get a string returned...as far as i can tell that works :)
 
@StephanKetterer Looks like it should work
 
yes it does :)
a giant step forward
 
That's good, because I can't see pastebin :)
 
Thanks a lot Robert, now atleast i can find out the "real" filetype
or variable type
 
Yeah - variable type is less confusing than filetype. So, I guess now all you need to do is do the right thing with the various types and you're there.
 
9:23 AM
stupid beginner question, is the whole code taken, or is it important that i have a function declaration above using it the first time ?
 
All of it
Well, it depends how it's running, but I'm assuming for your case all of it
If they've told you to make a function with a specific name, and they have an automated checker that calls that function, then it might be different.
 
got it :)
 
@AnttiHaapala that worked :)
 
because i know in like c, i have to prototype the function
 
Oh sorry, I actually misread your question
The function has to be defined first, yes. Sorry.
I was thinking of something completely different
However, this is valid:
 
9:27 AM
You don't need to prototype functions in python - see stackoverflow.com/a/25341254/838992 . It's very different to C. However, you do need to define it before you use it
Oops - sorry @Robert - put a comment in the middle of your explanation
 
def a():
    return b()

def b():
    return "Hello, world!"

a()
Even though b is defined below a, that's fine, because it's all parsed before the first call to a()
 
so in the part where i read the file, since wanna get the type there , i have to put all my get type stuff before it
ah i get it
 
Sorry - my define it before you use it was badly worded. It needs to be defined in the file where you use it is right. i.e. you need to give it a name. Not it needs to go before it's use in the file
 
so i don't have to move anything since the call to my audit function comes at the bottom of everything :_
 
In fact I'll edit that
 
9:29 AM
@JRichardSnape and now I put code in your explanation :)
 
was already wondering why mine worked :)
 
Bah - can't edit it. It will stay there as a testament to fingers going faster than brain
 
@StephanKetterer I think it'll run through your code top to bottom, but until you try to actually run anything, it'll forgive calls to functions that aren't there yet.
 
That's a good way to put it and (as usual) Martijn's answer that I linked to is very good.
 
ok, now on to sets, an unordered list with only unique elements
 
9:41 AM
Cool :)
 
@StephanKetterer Does that mean you got the csv one finished completely?
 
oh no :)
that is exactly where i am right now
i got this huge csv file and a list called FIELDS, its entries should function as the keys for a dictionary
the values for the dictionary should be sets that include the datatypes of those keys in the file
thats why i needed the get_the_type stuff
 
user4433485
Cabbage!
 
cabbage @katherina. How are you?
 
user4433485
I'm fine, you?
 
9:47 AM
Good. Thought you might still be sore. Getting used to the train? :p
 
user4433485
No :p I took my dads Plymouth today =D
 
user4433485
he felt sorry :p
 
:D
@StephanKetterer OK - got you. But you've got the reading file code and the get_the_type code - so now just to put the types into a set, right?
 
can we please not use the word "just" :)
i might jump off my balcony otherwise
 
user4433485
@JRichardSnape But atleast, no train for me today =D
 
9:53 AM
@JRichardSnape the problem is, what i need ( atleast that how i picture it in my mind, is a set, that contains the datatypes of an entire column)
 
@StephanKetterer Hmm - rethinks strategy for trying to make tasks seem accessible. You're right - 'just' is all relative. My advice always - start small - even directly in the interpreter. Make a small set. Add a couple of members. Try and add a duplicate, see what it does.
 
oh i already know it does to take duplicates
does not
my problem atleast so me is different
 
user4433485
oh almost forgot, did @MartijnPieters win ?
 
@Katherina see that blue next to my name?
:-)
 
Behold the diamond
 
user4433485
9:57 AM
ohh ! Well done!
 
i go through all the rows one by one, and in each row go through the cols and then print out the element
but now , i need a set that contains all the datatypes of a specific row, and i have no idea how to accomplish that in the mentioned above structure
 
314
Q: April 2015 Community Moderator Election Results

Shog9Stack Overflow's 6th moderator election has come to a close, the votes have been tallied, and the 3 new moderators are: They'll be joining the existing crew shortly — please thank them for volunteering, and share your assistance and advice with them as they learn the ropes! For details on ...

 
user4433485
Gongratz @Martijn
 
I regret to inform you that there is no Internet meme image that can adequately capture my feelings about this moment. EXCEPT THIS ONE i.imgur.com/GbEwBl0.jpgJeff Atwood ♦ 7 hours ago
Congrats @MartijnPieters :-)
 
9:59 AM
@thefourtheye I'm far from worthy of that comment, that was addressed to Bill!
May I one day be 10% of the moderator he was.
 
@StephanKetterer This might help you think about it - you need to add something (the type) to the same set on each iteration of the loop. You need one set per member of FIELDS. Do you need to create the set(s) before, during or after the loop?
 
@MartijnPieters Well, time will answer that :D
 
user4433485
@thefourtheye Is it time for whisky and smoke alrdy?
 
@Katherina Sure, why not? ;-)
 
@JRichardSnape thats what i thought all along.. i need several sets, so i can adress them in the loop
so i need a list of sets i guess, the index of the set, i could just use the same values as in FIELDS i guess
 
10:06 AM
@StephanKetterer You've got it. Except I'd use a dict of sets, rather than a list - given your ultimate requirement.
 
oh my final outcome should be a dict already, called fieldtypes, right now an empty dict
this is not right yet, i have a feeling it will overwrite the value and not add to it
 
@StephanKetterer Sure. Well if you set it up with keys from FIELDS and empty sets for values - you can just access those sets in your inner loop and work on them before you ultimately return
@StephanKetterer Very nearly there. You need to think of two things. 1. Where do you set the dict up with one set per field name (hint: you don't - so where should you?) 2. Do you want to set the value of fieldtypes[col], or .add( to it? As you suggest, one will overwrite, the other...
 
@JonClements Why did you fail on me?! :(
Gratz @MartijnPieters
Morning all
 
ok.. have to think about it :)
but atleast it seems i am moving in the right direction
i think .append might work, i hope it works even though its initially empty
but hmm.. how to setup the dict, it is defined just as filedtypes={}
 
10:32 AM
which web server should i use if my application is in python ? Apache or nginx ?
 
You should always choose Nginx
 
okey
 
10:44 AM
@MartijnPieters mine only :d
surely after no one dares to spell your name incorrectly you'd go after those who abuse my name :D
 
@JRichardSnape could you maybe give me a hint how to initialise the dict with a set as a value ?
 
@StephanKetterer Sure. Here's a basic one
d = {}
 
thats an empty one i thought
i have that :)
 
d['mykey'] = set()
 
10:49 AM
then have a look at d
 
ah so you set it up individually
not a general declaration
 
then, maybe try d['my_other_key'] = set()
have another look at d
and relate what you're doing to what you want to do with FIELDS
 
gimme a sec i will try :)
maybe like this in my loop
            fieldtypes[col]=set()
            fieldtypes[col].append(get_the_type(row[col]))
hmm that is probably not right, since that would mean whenever i go through the loop, i set the value as an empty set again :)
:(
 
You are correct in your diagnosis of what's wrong.
 
hehe :)
 
11:00 AM
Also - set doesn't have .append( is has .add( It's a good idea to get used to looking at the docs.
 
yes damn . set again :)
so i have to setup the value as a set somewhere else
maybe
 
You need a setup loop, before you enter your processing loop , it will hold the first line of what you pasted above. The second line would work if it said addand rightly belongs in your processing loop.
 
for col in FIELDS:
fieldtypes[col]=set()
 
Think of the logic: Set up the empty sets before I process, add to the appropriate set each time I process a value.
 
before my for row in reader
 
11:03 AM
BINGO!
 
wow, got it before reading your help
moving closer and closer, might even finish it this month at this pace
what i have thus far :) pastebin.com/1nrDLUSh
still get cryptic errors though :P
 
GIVE THIS @JRichardSnape a medal!
 
unfortunately i had nothing to trade but poker lessons :P
 
11:19 AM
@StephanKetterer Well - your code runs fine for me except your audit_file() doesn't return anything and should return the fieldtypes you have so carefully constructed :D
 
as for cryptic errors - they most certainly are cryptic if you don't put them in your pastebing
 
but - if it falls over - I suspect that a column in your FIELDS list isn't in your file
also - you haven't corrected FIELDS to fields in your audit_file(). And with that - I'll have to leave it, I think
@AnttiHaapala - I like that
 
oh , the error i get is from the grader i think :)
but it has to be something super minor, i posted it on their forums and tonight they will reply
thank you !!!
 
11:23 AM
i76uztuji76ujgtrzuji
 
cbg
 
@poke Is that a puzzle? Should we be busily trying to decrypt?
cbg all
 
Uhm. I just fist-rolled over my keyboard. But feel free to interpret it as a puzzle. So yes, it’s a puzzle!
 
Are questions asking to explain code written by someone else on-topic? The code in question uses an unspecified module, but I think I've tracked it down. stackoverflow.com/questions/29795516/…
 
@poke I just decoded it: 'Pineapple!? Lettuce?' Unfortunately, this margin is too small to include the decryption allgorithm
allgorithm? allgorithm!?!? algorithm, man!
@PM2Ring off-topic IMHO
 
11:30 AM
@MartijnPieters Congratulations to the Diamond Python Ninja!
 
@JRichardSnape Incredible! That’s correct!
 
@JRichardSnape I see that poke disagrees. :)
 
@JRichardSnape my python systems are deployed using make
 
cbg all
 
cbg @JonC
 
11:35 AM
cbg
 
Great to see @Martijn managed to get a 1st round win :)
 
@JonClements for moderator :D
6
2016
 
@AnttiHaapala my Python "systems" are deployed using a variety of cobbled together instructions :(
 
guess we're going to have to start answering Python questions now :p
 
11:36 AM
The "beauty" of being an academic
 
@PM2Ring Needs more Ninja outfit! :-)
 
yeah hope martijn takes the modship seriously
 
cbg @JonC :-)
 
cbg @JonC
 
@Zero thanks for your email :p
 
:22850083 who knows.... it's a long time way :p
 
Yeah :)
 
@vaultah your q^ has score of 20, have to make it hotter :D
 
@JonClements I think a team of private detectives watching out for poor bacon sandwich control might be effective ;-)
 
Must remember that when @Martijn speaks to not think: "oh gawd... what's happened to have a mod in here..." :p
 
11:39 AM
@PM2Ring I just don’t care enough and want to help instead :/
@JonClements You mean “guess we finally get rep for Python answers”? ;P
 
@poke yes.... that's the one :p
 
That script I posted a few weeks ago does the right thing. :) It signifies room owners with `*` and mods with `◆` (of course). Eg,
Martijn Pieters ........ 21:36:23 04/22/15 355646 * ◆
@poke I can relate to that.
 
TIL that room owners have italic names.
 
@Kevin I'm glad you're paying attention!? :p
 
11:46 AM
@poke It'd be nice if the OP verified that I've identified the correct module that contains the Problem class. And made it a bit more clear what they don't understand.
 
I have no excuse.
 
Right... had better get back to deciphering what the hell a client is asking me... rbrb for a bit
 
Is it appropriate to test inequality of booleans using is not ? I'm inclined to think it's ok (but I think ^ is better). See here stackoverflow.com/a/29790806/4014959 for context.
@Kevin FWIW, I hadn't noticed it before, either (or if I had, I'd forgotten :) ). OTOH, I'm not a room owner... :)
 
@PM2Ring the docs guarantee that "[bool's] only instances are False and True", so theoretically, is is safe to use. I don't consider it idiomatic, however.
 
11:56 AM
There's some danger in thinking that an expression has a boolean result when it doesn't. For example, (a or b) is (c and d) may have surprising results if a,b,c, or d are not booleans.
In that case, it's possible that a or b has the same truthiness as c and d, but the expression evaluates to False anyway.
 
@PM2Ring you use is not only if the possible values are something like False, True, None, 0 and 1 and you need to distinguish between all of them
 
Ex.
>>> a = 4
>>> b = 8
>>> c = 15
>>> d = 16
>>> (a or b) is (c and d)
False
>>> (a or b) and (c and d)
16
 
@Kevin perfectly makes sense.. (at least for me)
 

« first day (1649 days earlier)      last day (3299 days later) »