Assigning file to a variable to compare python

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-1
down vote

favorite












I would like to assign the values Fusion_1 == sorted_files[-1]
Fusion_2 == sorted_files[-2]
in my code below, but I am getting following error:



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)









share|improve this question













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 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














up vote
-1
down vote

favorite












I would like to assign the values Fusion_1 == sorted_files[-1]
Fusion_2 == sorted_files[-2]
in my code below, but I am getting following error:



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)









share|improve this question













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 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












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I would like to assign the values Fusion_1 == sorted_files[-1]
Fusion_2 == sorted_files[-2]
in my code below, but I am getting following error:



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)









share|improve this question













I would like to assign the values Fusion_1 == sorted_files[-1]
Fusion_2 == sorted_files[-2]
in my code below, but I am getting following error:



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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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
















  • 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















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

















active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay