Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Iam new to Python Need Help
#1
Hello All,

I tried running the below program in the 'Python 2.7.14 Shell', but I did not get any output at the end of the program.

f = open("C:/test/my_data.txt")
h = f.readline()
lines = f.readlines()
# select dno,sex,sum(sal) from emp
group by dno,sex;
res = {}
dno = w[-1].split("\n")[0]
sex = w[-2]
mykey = (dno,sex)
sal = int(w[2])
if res.get(mykey) == None:
res[mykey] = sal
else:
res[mykey] += sal
print("aggregations",res)


// my_data contains the following data :

id, name, sal, sex,deptno
101, Amar, 2000, M 11
102, Sai, 3000, F 11
103, Pran, 5000, M 12

Please help me
Reply
#2
(May-24-2018, 03:33 PM)hitesh222002 Wrote: f = open("C:/test/my_data.txt")
(May-24-2018, 03:33 PM)hitesh222002 Wrote: // my_data contains the following data :

Your data is in a file named my_data, but the program is reading my_data.txt. Those are not the same thing. There's no output, because there's no input.
Reply
#3
well even if the indentation is correct, this code would raise an exception because w is not defined. So you get a Traceback.
Do as Larz60+ advised you - put your code in python tags with correct indentation. Post also Full traceback you get in error tags
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020