@farhana Yes, if you want each project in a separate Git repository, you must create a new Git repository for each project. — Code-Apprentice25 secs ago
What's a readable way to write a bunch of (nested) if statements and run a specific line of code if none of the ifs triggered? My current solution abomination:
for arg in sys.argv[1:]:
if arg.startswith('-'):
arg = arg.lstrip('-')
if arg == 'foo':
... # handle the argument
elif arg == 'bar':
... # handle the argument
else:
break
continue
else:
... # handle the argument
continue
else:
return
raise Exception('Unknown argument: {}'.format(arg))
basically, I want to throw an exception if arg starts with - but isn't -foo or --foo or -bar or --bar
I will give credit for this answer if someone gives credit for my question but not before. My question's score is 0 currently. Thanks! — Geoffrey Anderson2 mins ago
Hey guys, how's it going? I've been teaching myself how to program for a little bit over a year now, and I'm about 5 months into what I'd call my first large project (over 1000 lines of code and counting), and I had a bit of a weird question. Where and when do I write tests?
I haven't written a single one for the past five months, and debugging my code has been a bit of a nightmare, but I just don't know where to start. Do I begin testing code I already wrote? Do I write tests before or after I write some new code? Should I test every feature and module in isolation, or should I string them together in logical ways and work from there? Do I need to randomize data each time, or should I stick to the same cases I know are going to be a problem each time?
Should all tests be contained in the same file, or should they be in the file where the actual code was written?
Sorry about the wall of text, I'm just really confused as to where to start. A lot of sites explain how to write tests, but not when and where.
As I understand there are multiple approaches to the problem, but the general consensus is "tests are good, have more of those". Some people will even vouch for writing tests before you write code, as a form of test-driven development
I believe there are various paradigms and kinds of tests (unit vs integration, for instance), and I don't personally test my code so I only have vague generic guidance :P But this has come up several times in the room
I'm not against retroactively testing my code, I was just wondering if that was an option in the first place. Glad to know that it is :). I'll try out test driven development
for the feature I'm currently working on, and see how that goes. I'll also start adding tests in for the more bug-prone areas of my code, and work from there to cover the whole codebase.
So would they go in a seperate folder called tests?
If they were within the same file, then each time that module was called, all the code inside of would execute, including the tests within. Sorry if that doesn't make sense, I am quite new to this.
If I import foo.py, and I have a function called foo_test() that I call in foo.py, then importing foo.py would test it at the same time.
It depends. I've come to understand pytest is the quickest to get tests off the ground, but unittest is a part of the standard library, so there's better support for it (?).
I do use a lot of logging during runtime, and in my case, considering how I use said logs, a good rule of thumb would be to write a test for every log message :). Scrolling through the log and checking every message making sure nothing is out of the ordinary can get tedious sometimes.
Thanks so much for all the help by the way, your answers really cleared things up for me.
how do you create a "quote - generator" - i +/- know how a NN works, but I cannot figure out how you can receive an quote without any input X
e.g. i take a text, create a word_int_dictionary and a int_word_dictionary secondly, i convert my text to integers third, i create input data, e.g. 5 words and for the output (y) i take the 6th word ( and shift to the next data input etc...)
then, i create a NN, with maybe a wordembedding + LSTM + dense end try to predict the next word (y)
--- no problems so far ---
but then i want to use, my network, to generate some text... but at this moment, i don't have anything .... no 5 words wich can predicht me the 6the
i know a markov chain, can also solve it, (and probably much easier) but for the sake of practise, i would like to use a NN
maybe i should start each 'document' with [ 0,9,3,7,4,0,3 ] <-- a random combination of numbers with size N (whereby N is the size of my training length )
(in this case 7)
and after the last Number, he might have learned the start of the real sentence?
and if i want to have a random quote i only have to doe something like model.predict([7,9,3,9,2,1,0,3,2], verbose=0)
maybe i don't even need digits from 0 to 9,
0 to 1 should also be fine, and i can tokenize them as special so that a 0 or 1 in the text, is not the same as this one
This is used by content extraction tools like Apache Tika. The existing distro is outdated, so I've forked and added in a change to fix it. Steps to install can be found here.