-
• #27
also looking into PyCharm fyi
-
• #28
I wouldn't recommend using PyCharm straight off the bat. It can end up hiding too much of the workings before you really understand it.
I think using sublime and a pylinter so you can check your work as you go.
-
• #29
Not like this:
print ("{0}".format(*row)+" is the callsign given to {1}".format(*row)+" which is in the {2}".format(*row)+" Area")
Like this:
print ("{0} is the callsign given to {1} which is in the {2} Area".format(*row))
-
• #30
A numpty question but what is the difference between using something like Sublime over TextMate. I'm starting to learn Python and am playing around with TextMate. I don't know enough about how Python works to understand what I might need from an editor (i.e. the kind of fuller Python-specific IDE productivity features that you see in various equivalent MS tools). But as you suggest, I sense there is merit in getting to grips with how everything hangs together before trying something more advanced.
-
• #31
disclaimer - this might all be bollocks
Textmate is great, but if you want to ever be seen coding in a cafe with a piccolo/flat white then Sublime/Atom is the way to go./s
I think people started moving away from Textmate and more to Sublime/Atom because you can extend them easily with things like linters (to check code) and git integrations (for versioning/collaboration), it's still a solid editor though. With Python you don't really need a hardcore IDE like Visual Studio because you don't require the build tools of a language like C++.
I think so long as you're looking a the mistakes you're making and understanding what the cause of them is then you'll be progressing. I definitely recommend writing scripts and executing them in the command line as opposed to writing them in the interactive python prompt.
A few sites I found really helpful, depending on where your skills are at:
Codeacadamy
Making a blog
Thinking more like a computer scientist
Project euler -
• #32
Yeah, makes sense. Thank you.
-
• #33
interesting. and useful, thanks.
I've been using jupyter so far to go through all these mini exercises that I need to do in prep for my interview on Friday (Data Science course, hopefully funded by work)
I like the way you can just jump back and forward without having to save .py files and switch programs to run them.
1 Attachment
-
• #34
Where's the DS course? I just did one at General Assembly
-
• #35
its a 2 year part time MSc at Birkbeck which seems a bit daunting but the modules look good and the whole subject matter should be immediately applicable at work
Which one did you do? I take it it was much shorter than that?
-
• #36
One of the final exercises in the prep pack
This is my code to solve the attached. It works, but can someone tell me if there's a better way to do this and comment on my "style" ? Much appreciated...
first = input("Enter the first number, (0 to finish): ") firstint = int(first) finished = False while not finished: next = input("Enter the next number, (0 to finish): ") nextint = int(next) if nextint == 0: finished = True elif nextint > firstint: print("Up") firstint = nextint elif nextint == firstint: print("Same") firstint = nextint elif nextint < firstint: print("Down") firstint = nextint
1 Attachment
-
• #37
and a variation of the above, which is the 'hardest' in the document:
first = input("Enter the first number, (0 to finish): ") firstint = int(first) a = "" finished = False while not finished: next = input("Enter the next number, (0 to finish): ") nextint = int(next) if nextint == 0: finished = True elif nextint > firstint: q = "Up" a = a+" "+q firstint = nextint elif nextint == firstint: q = "Same" a = a+" "+q firstint = nextint elif nextint < firstint: q = "Down" a = a+" "+q firstint=nextint print(a)
1 Attachment
-
• #38
here's the document in case anyone is interested. I can share my notebook with all the solutions.
1 Attachment
-
• #39
✅ 80% on entrance exam = unconditional offer
-
• #40
tonight's work....it ain't perfect, and probably not the best way to do this... but it is good practice doing if/elif etc! tried to add a few arguments to catch silly entries like multiple spaces, special chars etc
(I know I could validate against OS codepoint table, but that's not the point)
print('This tool breaks down UK postcodes to their component parts') exit=False while exit is False: postcode=input('Please enter your postcode (0 to exit): ').upper() if (' ' in postcode)==True: postcode=' '.join(postcode.split()) elif (' ' in postcode)==False: if len(postcode)==5: postcode=postcode[:2]+' '+postcode[2:] elif len(postcode)==6: postcode=postcode[:3]+' '+postcode[3:] elif len(postcode)==7: postcode=postcode[:4]+' '+postcode[4:] if (len(postcode)>8 and str(postcode)!='0') and set('[~!@#$%^&*()_+{}":;\']+$').intersection(postcode): print('Your postcode is too long and contains an illegal special character, please try again') elif (len(postcode)<6 and str(postcode)!='0') and set('[~!@#$%^&*()_+{}":;\']+$').intersection(postcode): print('Your postcode is too short and contains an illegal special character, please try again') elif len(postcode)>8 and str(postcode)!='0': print('Your postcode is too long, please try again') exit=False elif len(postcode)<6 and str(postcode)!='0': print('Your postcode is too short, please try again') exit=False elif set('[~!@#$%^&*()_+{}":;\']+$').intersection(postcode): print('Your postcode contains an illegal special character, please try again') exit=False elif str(postcode)=='0': print('Goodbye') exit=True elif len(postcode)>=6 and len(postcode)<=8: length=len(postcode) outward_code=postcode.split(' ')[0] if len(outward_code)==2: postcode_area=outward_code[:1] postcode_district=outward_code[1:2] elif len(outward_code)==3 and outward_code[1:2].isdigit(): postcode_area=outward_code[:1] postcode_district=outward_code[1:3] elif len(outward_code)==3 and not outward_code[1:2].isdigit(): postcode_area=outward_code[:2] postcode_district=outward_code[2:3] elif len(outward_code)==4: postcode_area=outward_code[:2] postcode_district=outward_code[2:4] inward_code=postcode.split(' ')[1] postcode_sector=inward_code[:1] postcode_unit=inward_code[1:3] print('') print(postcode+' breaks down to:') print('Outward Code: '+outward_code) print('Postcode Area: '+postcode_area) print('Postcode District: '+postcode_district) print('Inward Code: '+inward_code) print('Postcode Sector: '+postcode_sector) print('Postcode Unit: '+postcode_unit) print('') exit=False
-
• #41
is there a list of rules about what order if statements should go in?
for example if I put this
elif (len(postcode)<6 and str(postcode)!='0') and set('[~!@#$%^&*()_+{}":;\']+$').intersection(postcode): print('Your postcode is too short and contains an illegal special character, please try again')
after this
elif set('[~!@#$%^&*()_+{}":;\']+$').intersection(postcode)
and enter "n%"
then the condition is met and it just tells me that it contains a special char but not that it is too short.
-
• #42
I'd remove the spaces before you break down the postcode.
If I put in 'A B123XY'
then the breakdown isn't right.But it's trivial to fix someone putting a space in the wrong place since every postcode has a space before the last 3 characters, regardless of whether it's 5, 6 or 7 characters long.
As to the order of statements, you would put the most restrictive first.
Or you could check everyone and set a flag somewhere.But I'd avoid putting every combination of error messages in.
You've only got 3 things to check for.
Too long, too short, bad characters. So it's manageable to put the combinations in (e.g. too long and bad characters). But consider if you had a dozen things to check for. You'd have a screen full of elifs and nested crap. Easier to check one thing at a time and potentially just have two error messages.
"Too long"
"Bad characters"isValid = true if length < 6: isValid = false if length > 8: isValid = false if set('[~!@#$%^&*()_+{}":;\']+$').intersection(postcode): isValid = false if isValid == false: print "something's wrong with the postcode"
etc.
Can simplify the stuff where you're working out the parts of the postcode too
print('This tool breaks down UK postcodes to their component parts') exit=False while not(exit): postcode=input('Please enter your postcode (0 to exit): ') postcode=str(postcode).upper().replace(" ", "") valid_postcode = True if str(postcode) == '0': print('Goodbye') exit = True else: if set('[~!@#$%^&*()_+{}":;\']+$').intersection(postcode): print('Your postcode contains an illegal special character, please try again') valid_postcode = False if len(postcode) < 5: print('Your postcode is too short, please try again') valid_postcode = False if len(postcode) > 7: print('Your postcode is too long, please try again') valid_postcode = False outward_code = postcode[:-3] inward_code = postcode[-3:] postcode_area=outward_code[:-2] postcode_district=outward_code[-2:] postcode_sector=inward_code[:1] postcode_unit=inward_code[1:] if valid_postcode: print('') print(outward_code+' '+inward_code+' breaks down to:') print('Outward Code: '+outward_code) print('Postcode Area: '+postcode_area) print('Postcode District: '+postcode_district) print('Inward Code: '+inward_code) print('Postcode Sector: '+postcode_sector) print('Postcode Unit: '+postcode_unit) print('')
(caveat - I probably have just as many bad habits as you, I've only been messing about in Python for a few weeks too)
-
• #43
thanks, a lot of that makes sense. I don't think I can avoid all the ifs, as postcodes like n1 1ab and sw1w 1ab are treated differently, but it is definitely neater!
Is there a way to measure performance as with SQL summary statistics and execution plans?
(caveat - I probably have just as many bad habits as you, I've only been messing about in Python for a few weeks too)
hence me posting.. i don't want them to become habits!
had you never done Python before going on the course?
Going on a 3 day course end of this month/early may which should be good. I think the main focus will be pandas and numpy
-
• #44
Anyone used Scrapy? May need some help later.
-
• #45
learning functions.
can someone please run this and let me know if I'm being long winded / over complicating things or if it is OK?
I'm sure I've already got some bad habits so would really appreciate some constructive feedback!
import getpass actual = {"username": "", "password": ""} attempt = {"username": "", "password": ""} def actual_credentials(): print("Choose username:") username=input() actual["username"] = username print("Choose password:") password=getpass.getpass() actual["password"] = password def attempt_credentials(): print("Enter username:") username=input() attempt["username"] = username print("Enter password:") password=getpass.getpass() attempt["password"] = password def main(): exit=False while exit is False: word=input("Continue typing, lock (l) or quit (q)? ") if word!="l" and word!="q": exit=False elif word=="l": x=False while x is False: attempt_credentials() if actual["username"]!=attempt["username"] or actual["password"]!=attempt["password"]: print("Username or password are incorrect") x=False else: print("You're in!") x=True elif word=="q": print('Thanks, goodbye!') exit=True actual_credentials() main()
-
• #46
I'm not a python dev and I don't really know what I'm doing but here are my thoughts.
Long nested loops like in your main function get really hard to follow very quickly. Ideally you never want to go deeper than 1 loop. Try and keep your variable names meaningful too, 'x' isn't a great name. In line 26-27 you're catering for a case where nothing happens, so you don't need to cover it.
Attached my small refactor
1 Attachment
-
• #47
Thanks muchly. 26/27 were so you keep entering random text until you decide to quit or lock it but yes I will study your version as it seems much simpler and cleaner at first glance! Thanks again
-
• #48
.
-
• #49
MassifCentral are looking for developer to help take our PYTHON software to the next level...
Quick Backstory: We illustrate people's challenges & achievements. It's mainly cycling but we also cover running, triathlon and hiking, and occasionally we do corporate work illustrating businesses etc. We have some great partners like Haute Route, Nocturne, Threshold and Hot Chillee.
http://www.themassifcentral.co.ukMost of our challenge illustrations rely on GPX and CSV data. Initially we extrapolated these 'by hand' and used architectural CAD packages (our background) to get the skeletons of the designs done. A couple of years ago we invested in some basic software that allows us to manage and manipulate GPX's on the fly, which sped up the process considerably.
We are now looking to take that in-house software to the next level. We've sought investment/fundraising for this but it ain't happening so we are now looking for a developer who can work on it in their spare time and be rewarded with equity. The immediate challenge is get the current software to a point where people outside of the company (i.e. customers) can use it to create their own simple prints, which we then fulfil for them.
Down the line, there is the more complex task of marrying the objective GPX data with the more subjective mapping decisions that we make whilst designing the prints (e.g. which towns/villages to include/exclude, climbs and landmarks).
We are based in East London and can offer workspace if needed but we are also open to remote workers etc.
Drop me a line here or at howardsmith (at) themassifcentral.co.uk if you would like to learn more.
Thanks
HMS -
• #50
@duncs - I'm just about to start this, how'd you find it. PM me if you'd prefer.
@ObiWomKenobi - think you're doing this at the same time as my wife. I blame her for my life choices.
Currently working my way through calculus and 'Learning Python the hard way'.
Quite apprehensive all in all.
I'm still very much learning and using Jupyter