Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #40474 > unrolled thread
| Started by | io <maroso@libero.it> |
|---|---|
| First post | 2013-03-04 19:06 +0000 |
| Last post | 2013-03-04 16:19 -0500 |
| Articles | 12 — 9 participants |
Back to article view | Back to comp.lang.python
Python script not working on windows 7 but works fine on linux io <maroso@libero.it> - 2013-03-04 19:06 +0000
Re: Python script not working on windows 7 but works fine on linux Christian Gollwitzer <auriocus@gmx.de> - 2013-03-04 20:20 +0100
Re: Python script not working on windows 7 but works fine on linux io <maroso@libero.it> - 2013-03-04 19:58 +0000
Re: Python script not working on windows 7 but works fine on linux ian douglas <iandouglas736@gmail.com> - 2013-03-04 11:20 -0800
Re: Python script not working on windows 7 but works fine on linux io <maroso@libero.it> - 2013-03-04 19:59 +0000
Re: Python script not working on windows 7 but works fine on linux Chris Angelico <rosuav@gmail.com> - 2013-03-05 07:56 +1100
Re: Python script not working on windows 7 but works fine on linux Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-05 01:58 +0000
Re: Python script not working on windows 7 but works fine on linux Andrew Berg <bahamutzero8825@gmail.com> - 2013-03-04 20:25 -0600
Re: Python script not working on windows 7 but works fine on linux 88888 Dihedral <dihedral88888@googlemail.com> - 2013-03-04 18:58 -0800
Re: Python script not working on windows 7 but works fine on linux 88888 Dihedral <dihedral88888@googlemail.com> - 2013-03-04 18:58 -0800
Re: Python script not working on windows 7 but works fine on linux Wolfgang Strobl <news4@mystrobl.de> - 2013-03-04 20:30 +0100
Re: Python script not working on windows 7 but works fine on linux Terry Reedy <tjreedy@udel.edu> - 2013-03-04 16:19 -0500
| From | io <maroso@libero.it> |
|---|---|
| Date | 2013-03-04 19:06 +0000 |
| Subject | Python script not working on windows 7 but works fine on linux |
| Message-ID | <5134f0d1$0$40360$4fafbaef@reader1.news.tin.it> |
The following scripts are working fine on linux but, using the same
version, can't work on windows because i receive the following message:
Script:
import json
import urllib
import csv
url = "http://bitcoincharts.com/t/markets.json"
response = urllib.urlopen(url);
data = json.loads(response.read())
f = open("/home/io/btc_trading/markets.csv","wb")
c = csv.writer(f)
#apre un file di testo e legge il contenuto del file inserendolo in una
stringa
esclusioni_file = open('/home/io/btc_trading/exclusions.txt','r')
esclusioni = []
for line in esclusioni_file:
esclusioni.append(line.strip())
#print(esclusioni)
# write headers
c.writerow(["Currency","Symbol","Bid", "Ask", "Volume"])
for d in data :
if d["currency"] <> "SLL": #esclude la valuta di secondlife SLL
if d["bid"] is not None and d["ask"] is not None:
if d["symbol"] not in esclusioni:
#print d["symbol"]
c.writerow([str(d["currency"]),str(d["symbol"]),str(d
["bid"]),str(d["ask"]),str(d["currency_volume"])])
#esclusioni.close()
Windows error :
Traceback (most recent call last):
File "C:\btc_trading\scripts
\import_json_2_csv_from_web_and_exclusions.py", line 10, in <module>
f = open("/home/io/btc_trading/markets.csv","wb")
IOError: [Errno 2] No such file or directory: '/home/io/btc_trading/
markets.csv'
>>>
[toc] | [next] | [standalone]
| From | Christian Gollwitzer <auriocus@gmx.de> |
|---|---|
| Date | 2013-03-04 20:20 +0100 |
| Message-ID | <kh2s3i$md1$1@dont-email.me> |
| In reply to | #40474 |
Am 04.03.13 20:06, schrieb io:
> The following scripts are working fine on linux but, using the same
> version, can't work on windows because i receive the following message:
>
snip
> f = open("/home/io/btc_trading/markets.csv","wb")
> Windows error :
>
> Traceback (most recent call last):
> File "C:\btc_trading\scripts
> \import_json_2_csv_from_web_and_exclusions.py", line 10, in <module>
> f = open("/home/io/btc_trading/markets.csv","wb")
> IOError: [Errno 2] No such file or directory: '/home/io/btc_trading/
> markets.csv'
>>>>
Are you actually reading that error message? You have an absolute path
in script! This /home/io... would something like C:/btc_trading/... on
Windows.
This is not a Python question, it is a Linux/Windows question. Ask your
local IT guy.
Christian
[toc] | [prev] | [next] | [standalone]
| From | io <maroso@libero.it> |
|---|---|
| Date | 2013-03-04 19:58 +0000 |
| Message-ID | <5134fcf1$0$40360$4fafbaef@reader1.news.tin.it> |
| In reply to | #40475 |
Thanks, .... btw ...i'm the IT guy! I was missing the double slash as dougas suggested!++Thanks anyway.
[toc] | [prev] | [next] | [standalone]
| From | ian douglas <iandouglas736@gmail.com> |
|---|---|
| Date | 2013-03-04 11:20 -0800 |
| Message-ID | <mailman.2854.1362424842.2939.python-list@python.org> |
| In reply to | #40474 |
On 03/04/2013 11:06 AM, io wrote:
> esclusioni_file = open('/home/io/btc_trading/exclusions.txt','r')
>
> Windows error :
>
> Traceback (most recent call last):
> File "C:\btc_trading\scripts
> \import_json_2_csv_from_web_and_exclusions.py", line 10, in <module>
> f = open("/home/io/btc_trading/markets.csv","wb")
> IOError: [Errno 2] No such file or directory: '/home/io/btc_trading/
> markets.csv'
The error tells you everything you need to know: the file system has no
path/file called "/home/io/btc_trading/markets.csv"
I imagine your CSV file lives in a different location on your Windows 7
system (which also uses back-slashes '\' instead of forward-slashes '/',
so you'll need to maybe do a try/except around the open() call to open a
Windows path like open("c:\\users\\io\\Documents\\markets.csv") or
whatever. OR you'll need to do some OS detection ahead of time to set
the file path properly.
[toc] | [prev] | [next] | [standalone]
| From | io <maroso@libero.it> |
|---|---|
| Date | 2013-03-04 19:59 +0000 |
| Message-ID | <5134fd35$0$40360$4fafbaef@reader1.news.tin.it> |
| In reply to | #40476 |
Genius! The code i posted was an example. My real code was c:\btc_trading .... i was just missing the double slashes! Thanks , thankyou very much. :-)
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-03-05 07:56 +1100 |
| Message-ID | <mailman.2855.1362430590.2939.python-list@python.org> |
| In reply to | #40479 |
On Tue, Mar 5, 2013 at 6:59 AM, io <maroso@libero.it> wrote: > Genius! > > The code i posted was an example. > My real code was c:\btc_trading .... > > i was just missing the double slashes! > > Thanks , thankyou very much. > > :-) Even on Windows, you can use / as a directory separator. This generally saves you the trouble of switching to \\ for everything; though still, absolute paths are often wrong. But at least you can use relative paths safely! ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-03-05 01:58 +0000 |
| Message-ID | <51355152$0$30001$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #40476 |
On Mon, 04 Mar 2013 11:20:28 -0800, ian douglas wrote: > The error tells you everything you need to know: the file system has no > path/file called "/home/io/btc_trading/markets.csv" > > I imagine your CSV file lives in a different location on your Windows 7 > system (which also uses back-slashes '\' instead of forward-slashes '/', Windows understands forward slashes in paths too. You can make your code (almost) platform-independent, and avoid a lot of problems with unescaped backslashes, by always using forward slashes in paths. -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Andrew Berg <bahamutzero8825@gmail.com> |
|---|---|
| Date | 2013-03-04 20:25 -0600 |
| Message-ID | <mailman.2860.1362450348.2939.python-list@python.org> |
| In reply to | #40492 |
On 2013.03.04 19:58, Steven D'Aprano wrote: > Windows understands forward slashes in paths too. You can make your code > (almost) platform-independent, and avoid a lot of problems with unescaped > backslashes, by always using forward slashes in paths. Or use os.path.join, the entire purpose of which is to create suitable paths dynamically. -- CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1
[toc] | [prev] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2013-03-04 18:58 -0800 |
| Message-ID | <d448b5c5-9957-48bd-9061-b3496aff85a0@googlegroups.com> |
| In reply to | #40476 |
On Tuesday, March 5, 2013 3:20:28 AM UTC+8, ian douglas wrote:
> On 03/04/2013 11:06 AM, io wrote:
>
> > esclusioni_file = open('/home/io/btc_trading/exclusions.txt','r')
>
> >
>
> > Windows error :
>
> >
>
> > Traceback (most recent call last):
>
> > File "C:\btc_trading\scripts
>
> > \import_json_2_csv_from_web_and_exclusions.py", line 10, in <module>
>
> > f = open("/home/io/btc_trading/markets.csv","wb")
>
> > IOError: [Errno 2] No such file or directory: '/home/io/btc_trading/
>
> > markets.csv'
>
>
>
> The error tells you everything you need to know: the file system has no
>
> path/file called "/home/io/btc_trading/markets.csv"
>
>
>
> I imagine your CSV file lives in a different location on your Windows 7
>
> system (which also uses back-slashes '\' instead of forward-slashes '/',
>
> so you'll need to maybe do a try/except around the open() call to open a
>
> Windows path like open("c:\\users\\io\\Documents\\markets.csv") or
>
> whatever. OR you'll need to do some OS detection ahead of time to set
>
> the file path properly.
Well, I'll suggest an old trick I did long time ago to resolve
the platform dependent problem in python.
Just write a generator as a buffered input method to work under some
file of some OS correctly first, then you can pass the generator which
is tested rigorously to act properly in the function or the object which will
use the generator to sip up the data to perform jobs.
[toc] | [prev] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2013-03-04 18:58 -0800 |
| Message-ID | <mailman.2862.1362452346.2939.python-list@python.org> |
| In reply to | #40476 |
On Tuesday, March 5, 2013 3:20:28 AM UTC+8, ian douglas wrote:
> On 03/04/2013 11:06 AM, io wrote:
>
> > esclusioni_file = open('/home/io/btc_trading/exclusions.txt','r')
>
> >
>
> > Windows error :
>
> >
>
> > Traceback (most recent call last):
>
> > File "C:\btc_trading\scripts
>
> > \import_json_2_csv_from_web_and_exclusions.py", line 10, in <module>
>
> > f = open("/home/io/btc_trading/markets.csv","wb")
>
> > IOError: [Errno 2] No such file or directory: '/home/io/btc_trading/
>
> > markets.csv'
>
>
>
> The error tells you everything you need to know: the file system has no
>
> path/file called "/home/io/btc_trading/markets.csv"
>
>
>
> I imagine your CSV file lives in a different location on your Windows 7
>
> system (which also uses back-slashes '\' instead of forward-slashes '/',
>
> so you'll need to maybe do a try/except around the open() call to open a
>
> Windows path like open("c:\\users\\io\\Documents\\markets.csv") or
>
> whatever. OR you'll need to do some OS detection ahead of time to set
>
> the file path properly.
Well, I'll suggest an old trick I did long time ago to resolve
the platform dependent problem in python.
Just write a generator as a buffered input method to work under some
file of some OS correctly first, then you can pass the generator which
is tested rigorously to act properly in the function or the object which will
use the generator to sip up the data to perform jobs.
[toc] | [prev] | [next] | [standalone]
| From | Wolfgang Strobl <news4@mystrobl.de> |
|---|---|
| Date | 2013-03-04 20:30 +0100 |
| Message-ID | <5et9j855qil8rv1sc518fcqmdlubef18sf@4ax.com> |
| In reply to | #40474 |
io <maroso@libero.it>: >The following scripts are working fine on linux but, using the same >version, can't work on windows because i receive the following message: Thats because there is No such file or directory: '/home/io/btc_trading/ on that Windows PC. -- Wir danken für die Beachtung aller Sicherheitsbestimmungen
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2013-03-04 16:19 -0500 |
| Message-ID | <mailman.2856.1362432000.2939.python-list@python.org> |
| In reply to | #40474 |
On 3/4/2013 2:20 PM, ian douglas wrote:
> I imagine your CSV file lives in a different location on your Windows 7
> system (which also uses back-slashes '\' instead of forward-slashes '/',
Forward slashes work fine on Windows except for invoking the executable
at a Command Prompt command line, where '/' marks an option.
>>> open('/programs/python33/python.exe')
<_io.TextIOWrapper name='/programs/python33/python.exe' mode='r'
encoding='cp1252'>
--
Terry Jan Reedy
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web