Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #46061 > unrolled thread

Error when trying to sort and presnt a dictionary in python 3.3.1

Started byΝίκος Γκρ33κ <nikos.gr33k@gmail.com>
First post2013-05-26 04:11 -0700
Last post2013-05-26 09:09 -0700
Articles 4 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Error when trying to sort and presnt a dictionary in python 3.3.1 Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-05-26 04:11 -0700
    Re: Error when trying to sort and presnt a dictionary in python 3.3.1 Peter Otten <__peter__@web.de> - 2013-05-26 14:20 +0200
      Re: Error when trying to sort and presnt a dictionary in python 3.3.1 Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-05-26 05:58 -0700
        Re: Error when trying to sort and presnt a dictionary in python 3.3.1 Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-05-26 09:09 -0700

#46061 — Error when trying to sort and presnt a dictionary in python 3.3.1

FromΝίκος Γκρ33κ <nikos.gr33k@gmail.com>
Date2013-05-26 04:11 -0700
SubjectError when trying to sort and presnt a dictionary in python 3.3.1
Message-ID<95e674bf-0d96-479c-b7a4-9242768a7a46@googlegroups.com>
python3 pelatologio.py gives  me error in this line:

Traceback (most recent call last):
  File "pelatologio.py", line 283, in &lt;module&gt;
    ''' % (months[key], key) )
KeyError: 1

The code is:

#populating months into a dropdown menu
years = ( 2010, 2011, 2012, 2013 )
months = { 'Ιανουάριος':1, 'Φεβρουάριος':2, 'Μάρτιος':3, 'Απρίλιος':4, 'Μάϊος':5, 'Ιούνιος':6, \
	   'Ιούλιος':7, 'Αύγουστος':8, 'Σεπτέμβριος':9, 'Οκτώβριος':10, 'Νοέμβριος':11, 'Δεκέμβριος':12 }

print('''
<form method="post" action="">
	<select name="month">
''')
	
for key in sorted( months.values() ):
	print('''
		<option value="%s"> %s </option>
	''' % (months[key], key) )

[toc] | [next] | [standalone]


#46066

FromPeter Otten <__peter__@web.de>
Date2013-05-26 14:20 +0200
Message-ID<mailman.2172.1369570798.3114.python-list@python.org>
In reply to#46061
Νίκος Γκρ33κ wrote:

> python3 pelatologio.py gives  me error in this line:
> 
> Traceback (most recent call last):
>   File "pelatologio.py", line 283, in &lt;module&gt;
>     ''' % (months[key], key) )
> KeyError: 1
> 
> The code is:
> 
> #populating months into a dropdown menu
> years = ( 2010, 2011, 2012, 2013 )
> months = { 'Ιανουάριος':1, 'Φεβρουάριος':2, 'Μάρτιος':3, 'Απρίλιος':4,
> 'Μάϊος':5, 'Ιούνιος':6, \ 'Ιούλιος':7, 'Αύγουστος':8, 'Σεπτέμβριος':9,
> 'Οκτώβριος':10, 'Νοέμβριος':11, 'Δεκέμβριος':12 }

You have keys and values mixed up...
 
> print('''
> <form method="post" action="">
> <select name="month">
> ''')
> 
> for key in sorted( months.values() ):

and calling the value key doesn't help there.

> print('''
> <option value="%s"> %s </option>
> ''' % (months[key], key) )

At some point you have to admit that coding isn't your cup of tea.
Or Ouzo ;(

[toc] | [prev] | [next] | [standalone]


#46067

FromΝίκος Γκρ33κ <nikos.gr33k@gmail.com>
Date2013-05-26 05:58 -0700
Message-ID<9ea1331c-2c23-43db-a4d0-68f6cdd5f321@googlegroups.com>
In reply to#46066
Τη Κυριακή, 26 Μαΐου 2013 3:20:19 μ.μ. UTC+3, ο χρήστης Peter Otten έγραψε:

> At some point you have to admit that coding isn't your cup of tea.
> Or Ouzo ;(

And i didn't evne drank anyhting, iam sober! Imagine what i would have written if i had some shots of Ouzo :-)

I chnage my code to:

months = { 'Ιανουάριος':1, 'Φεβρουάριος':2, 'Μάρτιος':3, 'Απρίλιος':4, 'Μάϊος':5, 'Ιούνιος':6, \
	   'Ιούλιος':7, 'Αύγουστος':8, 'Σεπτέμβριος':9, 'Οκτώβριος':10, 'Νοέμβριος':11, 'Δεκέμβριος':12 }

print('''
<form method="post" action="">
	<select name="month">
''')
	
for key in sorted( months.keys() ):
	print('''
		<option value="%s"> %s </option>
	''' % (months[key], key) )
				
print('''
	</select> '''


Now, iam not getting any eroor from cmd when i 'python3 pelatologio.py' verythign interprets normally wiyohut an error.

BUT i kepp getting an internal server error when i try to run the script via a browser (Chrome).

python3 path is ok
uploaded as ascii
chmoded to 755 ok.

How in cmd i get no error while on browser i get internal server error?

[toc] | [prev] | [next] | [standalone]


#46079

FromΝίκος Γκρ33κ <nikos.gr33k@gmail.com>
Date2013-05-26 09:09 -0700
Message-ID<d99cbc52-d2c4-4ace-9be7-c13f43bfab73@googlegroups.com>
In reply to#46067
Τη Κυριακή, 26 Μαΐου 2013 3:58:12 μ.μ. UTC+3, ο χρήστης Νίκος Γκρ33κ έγραψε:
> Τη Κυριακή, 26 Μαΐου 2013 3:20:19 μ.μ. UTC+3, ο χρήστης Peter Otten έγραψε:
> 
> 
> 
> > At some point you have to admit that coding isn't your cup of tea.
> 
> > Or Ouzo ;(
> 
> 
> 
> And i didn't evne drank anyhting, iam sober! Imagine what i would have written if i had some shots of Ouzo :-)
> 
> 
> 
> I chnage my code to:
> 
> 
> 
> months = { 'Ιανουάριος':1, 'Φεβρουάριος':2, 'Μάρτιος':3, 'Απρίλιος':4, 'Μάϊος':5, 'Ιούνιος':6, \
> 
> 	   'Ιούλιος':7, 'Αύγουστος':8, 'Σεπτέμβριος':9, 'Οκτώβριος':10, 'Νοέμβριος':11, 'Δεκέμβριος':12 }
> 
> 
> 
> print('''
> 
> <form method="post" action="">
> 
> 	<select name="month">
> 
> ''')
> 
> 	
> 
> for key in sorted( months.keys() ):
> 
> 	print('''
> 
> 		<option value="%s"> %s </option>
> 
> 	''' % (months[key], key) )
> 
> 				
> 
> print('''
> 
> 	</select> '''
> 
> 
> 
> 
> 
> Now, iam not getting any eroor from cmd when i 'python3 pelatologio.py' verythign interprets normally wiyohut an error.
> 
> 
> 
> BUT i kepp getting an internal server error when i try to run the script via a browser (Chrome).
> 
> 
> 
> python3 path is ok
> 
> uploaded as ascii
> 
> chmoded to 755 ok.
> 
> 
> 
> How in cmd i get no error while on browser i get internal server error?

Its okey i made it work, it wasnt an actuap python issue but an .htaccess and .htpasswd problem.

All fine now!

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web