-1

I have the following code:

    def xyz(a):
       return 2*a
    def abc(b):
       return 4*b
    print "a is :: "+xyz(1)"b is :: "+abc(2)

and I would like my output to be like this - a is :: 2 b is :: 8. (that is, both in the same line).

tobiuchiha
  • 73
  • 1
  • 7
  • 2
    You need to keep your question to **one** issue per post, please. – Martijn Pieters Sep 16 '14 at 17:34
  • The code you describe doesn't really look like the code you show, so it's pretty hard to tell exactly what you're doing . . . – mgilson Sep 16 '14 at 17:34
  • @mgilson: They are asking 2 separate questions; I tried to edit this into shape before realising this. – Martijn Pieters Sep 16 '14 at 17:35
  • @MartijnPieters -- Ahh, yes, that clarifies it a bit. . . – mgilson Sep 16 '14 at 17:37
  • sorry for asking two questions in one post. there are two separate questions in this post. the code given is not for the second part. the second question starts with Now,... – tobiuchiha Sep 16 '14 at 17:37
  • @AnkurGupta: Split this out to two separate questions, although both are probably duplicates. – Martijn Pieters Sep 16 '14 at 17:38
  • Your print statement should be this : `print "a is :: "+str(xyz(1))+" b is :: "+str(abc(2))` – Nico Sep 16 '14 at 17:39
  • @MartijnPieters -- I will separate this in two questions, since one can post once in 90 minutes, I cannot do that now. And yes both these questions are related to the same code, but I don't know what do you mean by 'duplicates'. – tobiuchiha Sep 16 '14 at 17:52

1 Answers1

1

1)

print "a is :: %(xyz)s b is :: %(abc)s" % {'xyz':xyz(1), 'abc':abc(2)}

2) Like in the comment by @MartijnPieters you want to make a circular import that you should avoid. I am giving a link to avoid makeing a copy of a perfect topic about circular imports

Community
  • 1
  • 1
Vizjerei
  • 1,000
  • 8
  • 15
  • Much better already. However, your point 2 won't work; the OP wants to import names back from `main`. That requires an explanation about namespaces and the dangers of circular imports. – Martijn Pieters Sep 16 '14 at 18:13
  • @Vizjerei a,b,c are float type variables. I have already given some value to them in main.py and now I want to use these values for the same variables in xyz.py. When I used your method I got an error 'unsupported operand type(s): 'NoneType' and 'int''. – tobiuchiha Sep 16 '14 at 18:16