Assigning file to a variable to compare python
Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
I would like to assign the values Fusion_1 == sorted_files[-1]
in my code below, but I am getting following error:
Fusion_2 == sorted_files[-2]
Error:
Traceback (most recent call last):
File "test.py", line 10, in <module>
Fusion_1 == sorted_files[-1]
NameError: name 'Fusion_1' is not defined
Code:
import glob
import os
import csv
list_of_files = glob.glob('Fusion_*') # * means all if need specific format then *.csv
sorted_files = sorted(list_of_files, key=os.path.getmtime)
sorted_files[-1]
sorted_files[-2]
Fusion_1 == sorted_files[-1]
Fusion_2 == sorted_files[-2]
f = open('Fusion_1.csv')
csv_f = csv.reader(f)
Fusion_1 =
for row in csv_f:
Fusion_1.append(row[2])
Fusion_1.append(row[3])
Fusion_1.append(row[4])
f = open('Fusion_2.csv')
csv_f = csv.reader(f)
Fusion_2 =
for row in csv_f:
Fusion_2.append(row[2])
Fusion_2.append(row[3])
Fusion_2.append(row[4])
print Fusion_2
f.close()
Fusion_1 = set (Fusion_1)
Fusion_2 = set (Fusion_2)
print Fusion_1.difference(Fusion_2)
python csv file-comparison
migrated from unix.stackexchange.com Sep 13 at 17:55
This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.
add a comment |Â
up vote
-1
down vote
favorite
I would like to assign the values Fusion_1 == sorted_files[-1]
in my code below, but I am getting following error:
Fusion_2 == sorted_files[-2]
Error:
Traceback (most recent call last):
File "test.py", line 10, in <module>
Fusion_1 == sorted_files[-1]
NameError: name 'Fusion_1' is not defined
Code:
import glob
import os
import csv
list_of_files = glob.glob('Fusion_*') # * means all if need specific format then *.csv
sorted_files = sorted(list_of_files, key=os.path.getmtime)
sorted_files[-1]
sorted_files[-2]
Fusion_1 == sorted_files[-1]
Fusion_2 == sorted_files[-2]
f = open('Fusion_1.csv')
csv_f = csv.reader(f)
Fusion_1 =
for row in csv_f:
Fusion_1.append(row[2])
Fusion_1.append(row[3])
Fusion_1.append(row[4])
f = open('Fusion_2.csv')
csv_f = csv.reader(f)
Fusion_2 =
for row in csv_f:
Fusion_2.append(row[2])
Fusion_2.append(row[3])
Fusion_2.append(row[4])
print Fusion_2
f.close()
Fusion_1 = set (Fusion_1)
Fusion_2 = set (Fusion_2)
print Fusion_1.difference(Fusion_2)
python csv file-comparison
migrated from unix.stackexchange.com Sep 13 at 17:55
This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.
Voting to move this to StackExchange as it's apython
question and not a Unix question.
â Nasir Riley
Sep 13 at 15:01
2
==
is a comparison operator in Python, while=
is for assignment.
â Kusalananda
Sep 13 at 15:04
you are going to want to use=
â MattR
Sep 13 at 18:02
add a comment |Â
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I would like to assign the values Fusion_1 == sorted_files[-1]
in my code below, but I am getting following error:
Fusion_2 == sorted_files[-2]
Error:
Traceback (most recent call last):
File "test.py", line 10, in <module>
Fusion_1 == sorted_files[-1]
NameError: name 'Fusion_1' is not defined
Code:
import glob
import os
import csv
list_of_files = glob.glob('Fusion_*') # * means all if need specific format then *.csv
sorted_files = sorted(list_of_files, key=os.path.getmtime)
sorted_files[-1]
sorted_files[-2]
Fusion_1 == sorted_files[-1]
Fusion_2 == sorted_files[-2]
f = open('Fusion_1.csv')
csv_f = csv.reader(f)
Fusion_1 =
for row in csv_f:
Fusion_1.append(row[2])
Fusion_1.append(row[3])
Fusion_1.append(row[4])
f = open('Fusion_2.csv')
csv_f = csv.reader(f)
Fusion_2 =
for row in csv_f:
Fusion_2.append(row[2])
Fusion_2.append(row[3])
Fusion_2.append(row[4])
print Fusion_2
f.close()
Fusion_1 = set (Fusion_1)
Fusion_2 = set (Fusion_2)
print Fusion_1.difference(Fusion_2)
python csv file-comparison
I would like to assign the values Fusion_1 == sorted_files[-1]
in my code below, but I am getting following error:
Fusion_2 == sorted_files[-2]
Error:
Traceback (most recent call last):
File "test.py", line 10, in <module>
Fusion_1 == sorted_files[-1]
NameError: name 'Fusion_1' is not defined
Code:
import glob
import os
import csv
list_of_files = glob.glob('Fusion_*') # * means all if need specific format then *.csv
sorted_files = sorted(list_of_files, key=os.path.getmtime)
sorted_files[-1]
sorted_files[-2]
Fusion_1 == sorted_files[-1]
Fusion_2 == sorted_files[-2]
f = open('Fusion_1.csv')
csv_f = csv.reader(f)
Fusion_1 =
for row in csv_f:
Fusion_1.append(row[2])
Fusion_1.append(row[3])
Fusion_1.append(row[4])
f = open('Fusion_2.csv')
csv_f = csv.reader(f)
Fusion_2 =
for row in csv_f:
Fusion_2.append(row[2])
Fusion_2.append(row[3])
Fusion_2.append(row[4])
print Fusion_2
f.close()
Fusion_1 = set (Fusion_1)
Fusion_2 = set (Fusion_2)
print Fusion_1.difference(Fusion_2)
python csv file-comparison
python csv file-comparison
asked Sep 13 at 14:45
balaji balehead
1
1
migrated from unix.stackexchange.com Sep 13 at 17:55
This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.
migrated from unix.stackexchange.com Sep 13 at 17:55
This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems.
Voting to move this to StackExchange as it's apython
question and not a Unix question.
â Nasir Riley
Sep 13 at 15:01
2
==
is a comparison operator in Python, while=
is for assignment.
â Kusalananda
Sep 13 at 15:04
you are going to want to use=
â MattR
Sep 13 at 18:02
add a comment |Â
Voting to move this to StackExchange as it's apython
question and not a Unix question.
â Nasir Riley
Sep 13 at 15:01
2
==
is a comparison operator in Python, while=
is for assignment.
â Kusalananda
Sep 13 at 15:04
you are going to want to use=
â MattR
Sep 13 at 18:02
Voting to move this to StackExchange as it's a
python
question and not a Unix question.â Nasir Riley
Sep 13 at 15:01
Voting to move this to StackExchange as it's a
python
question and not a Unix question.â Nasir Riley
Sep 13 at 15:01
2
2
==
is a comparison operator in Python, while =
is for assignment.â Kusalananda
Sep 13 at 15:04
==
is a comparison operator in Python, while =
is for assignment.â Kusalananda
Sep 13 at 15:04
you are going to want to use
=
â MattR
Sep 13 at 18:02
you are going to want to use
=
â MattR
Sep 13 at 18:02
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52319318%2fassigning-file-to-a-variable-to-compare-python%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Voting to move this to StackExchange as it's a
python
question and not a Unix question.â Nasir Riley
Sep 13 at 15:01
2
==
is a comparison operator in Python, while=
is for assignment.â Kusalananda
Sep 13 at 15:04
you are going to want to use
=
â MattR
Sep 13 at 18:02