ValueError when importing unicode_literals from __future__
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
astral |
Fix Released
|
High
|
Simon Kennedy |
Bug Description
Windows 7, Python 2.7.11, Astral 1.1
This code works (from the example code at https:/
```
#!/usr/bin/env python
# encoding: utf-8
from __future__ import print_function
# from __future__ import unicode_literals
import datetime
from astral import Astral # pip install astral
city_name = 'London'
a = Astral()
a.solar_depression = 'civil'
city = a[city_name]
print('Information for %s/%s\n' % (city_name, city.region))
timezone = city.timezone
print('Timezone: %s' % timezone)
print(' Latitude: %.02f; Longitude: %.02f\n' % \
(city.latitude, city.longitude))
sun = city.sun(
print('Dawn: %s' % str(sun['dawn']))
print('Sunrise: %s' % str(sun[
print('Noon: %s' % str(sun['noon']))
print('Sunset: %s' % str(sun['sunset']))
print('Dusk: %s' % str(sun['dusk']))
```
Outputs:
```
M:\bin>python test.py
Information for London/England
Timezone: Europe/London
Latitude: 51.50; Longitude: -0.12
Dawn: 2009-04-22 05:12:06+01:00
Sunrise: 2009-04-22 05:48:46+01:00
Noon: 2009-04-22 12:58:56+01:00
Sunset: 2009-04-22 20:09:00+01:00
Dusk: 2009-04-22 20:45:39+01:00
```
But uncommenting `from __future__ import unicode_literals` it gives:
```
M:\bin>python test.py
Traceback (most recent call last):
File "test.py", line 10, in <module>
a.solar_
File "C:\Python27\
self.
ValueError: could not convert string to float: civil
```
Changed in astral: | |
status: | New → Confirmed |
importance: | Undecided → High |
assignee: | nobody → Simon Kennedy (sffjunkie) |
Changed in astral: | |
status: | Confirmed → Triaged |
Changed in astral: | |
status: | Triaged → Fix Committed |
Changed in astral: | |
status: | Fix Committed → Fix Released |
One fix:
Change: n(self, depression): depression, str):
def solar_depressio
if isinstance(
to: n(self, depression): depression, str) or isinstance( depression, unicode):
def solar_depressio
if isinstance(
---
Another fix:
Add as first import:
from __future__ import unicode_literals
In latitude(self, latitude), longitude(self, longitude), solar_depressio n(self, depression):
Change: depression, str):
if isinstance(
to: depression, unicode):
if isinstance(
---
For both, there may be other similar changes to make elsewhere in the code; tests should find them.