Python Forum

Full Version: Iam new to Python Need Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
(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.
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