Re: [Tutor] Naming variables
W dniu 2014-01-18 19:20, Pierre Dagenais pisze: I wish to fill a list called years[] with a hundred lists called year1900[], year1901[], year1902[], ..., year1999[]. That is too much typing of course. Any way of doing this in a loop? I've tried stuff like ("year" + str(1900)) = [0,0] but nothing works. Any solution? Hi, I don't know the solution, or if there is one. And because of that, if I were you I would try to contain this data in different way. Why not dictionary? years = {1900: [0,0], 1901: [0,0], ..., 1999: [0,0]} Initiating this dictionary with empty (or [0,0]) one hundred lists would be easy with for loop. Accessing/changing list representing particular year is much more easier: years[1980]. -- Best regards, Wiktor Matuszewski | Python 'py{}@wu{}em.pl'.format('wkm', 'ka') | newbie ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Naming variables
W dniu 2014-01-18 19:20, Pierre Dagenais pisze: I wish to fill a list called years[] with a hundred lists called year1900[], year1901[], year1902[], ..., year1999[]. That is too much typing of course. Any way of doing this in a loop? I've tried stuff like ("year" + str(1900)) = [0,0] but nothing works. Any solution? >>> y = 1900 >>> exec('year{} = [0, 0]'.format(y)) >>> year1900 [0, 0] But I still think, that solution with dict with lists is better. -- Best regards, Wiktor Matuszewski | Python 'py{}@wu{}em.pl'.format('wkm', 'ka') | newbie ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] most useful ide
W dniu 2014-02-02 18:56, Albert-Jan Roskam pisze: >> On 02/02/14 08:25, Ian D wrote: >> >>> Are there any recommendations for python ide's >> >> Lots depending who you ask... > > If you ask me: Spyder (free) or PyCharm (free for open source projects) ;-) There is also PyCharm Community Edition. Free for all projects. And if you'd ask me, it would be my answer. :) -- Best regards, Wiktor Matuszewski ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Project tree
Hi, let's assume I have this project tree: project_name/ |-src/ | |- __init__.py | |- moda.py | '- modb.py '- start.py And individual files contain: - modb.py: - def hello(txt): return "Hello " + txt + "!" def plus1(num): return num + 1 - moda.py: - import modb def hello_world(): return modb.hello("World") - start.py: - from src import moda, modb print(moda.hello_world()) print(modb.plus1(41)) __init__.py is empty (it's project for my purpose - I don't want to distribute it with pypi, I pulled out start.py form src folder to just run everything without opening src folder) Ok, so now executing start.py works in Python 2.7(*), but doesn't work in Python 3.4(**). Can someone, please, explain me why? What changed between 2.x and 3.x versions? *) - gives output: Hello World! 42 **) - gives error message: Traceback (most recent call last): File "E:\tests\project_name\start.py", line 1, in from src import moda File "E:\tests\project_name\src\moda.py", line 1, in import modb ImportError: No module named 'modb' -- Best regards, Wiktor Matuszewski ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor