Re: A trivial question

2011-09-29 Thread jitendra gupta
HI
The class Foo you have defined is local NameSpace for trial functioon, for
details http://docs.python.org/tutorial/classes.html

def trial():
class Foo(object):
def __init__(self):
print("Hello, world!")
   lacalClass = Foo()
>>>trial
"Hello, world!"

Thanks
Jitendra

On Thu, Sep 29, 2011 at 3:19 AM, Tayfun Kayhan wrote:

> I accidentally wrote such a code (below) while trying to write sth else for
> my application but i am now just wondering much how to run the class Foo, if
> it is possible. Is not it weird that Python does not give any error when I
> run it ? Sorry for that it's pretty unimportant question according to the
> other questions being asked here :D
>
> def trial():
> class Foo(object):
> def __init__(self):
> print("Hello, world!")
> trial() # not worked, as expected.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Unit Test case for complie/test

2013-02-22 Thread jitendra gupta
Hi,

I am working one tool, which will do compile/run the workspace (that code
is written on c/c++). on that my requirment is i need to compile subfolder
also, i have wrote code for that also.
My problem is  , i am unable to write the Unit test case for that.  Since
my method (called run_subfolder) is not retrurning any thing (this will
create one command line argument in that i  am adding subfolder condition
and passing to the another class which will do actual thing) . For this
method i need to write unit test case. Since i dont have to workspace also
, so that i can test this case . Please advise on this. what i need to do.
this is possible or not, if not why.

Some forum suggested use mox. but i dont have more idea on this . in mox
how i will get thet output of the function



Thanks
Jitendra Kumar
-- 
http://mail.python.org/mailman/listinfo/python-list


Unit test cases for Object intraction using mox/unittest

2013-03-08 Thread jitendra gupta
Hi

I need to write the unit test cases for similary kind of sitution.

I need to write the unit test case for Foo.testCall. for both case true or
false. I am unalbe to do that.

kindly please help me on this. as function is not returning any thing. from
google i got mox is good for this case. but i did not found any solution
for this case

**  Enter.py 
from run import RunComp

def  enter():
   runC = RunComp("ComName", "~/pathToHome")
   """ This is based on some database condition we are passing name true or
false  """
foo = Foo(true)
foo.testCall(runC)

if __name__ == "__main__":
   enter()

**

* foo.py
Class Foo():

 def __init__(self, found):

 self.found = found


def testCall(self, SomeClassObject):
   if self.found:
  RunCompObject.call_run("codeRun -s " + self.found)
   else:
  RunCompObject.call_run("codeRun")
*

** run.py **

from subprocess import call


class RunComp(object):

def __init__(self, com, home):

 self.comp = comp

 self.home = home



def call_and_raise(*args, **kwargs):

if call(*args, **kwargs):

  raise RuntimeError("LDF command failed!")

   def call_run(self, command):

if self.comp:

command = " ".join((command,myldfrc))

   call(command, cwd=self.home)



*


Thanks & Regards
Jitu
-- 
http://mail.python.org/mailman/listinfo/python-list


email varification using smtplib or any method

2009-02-20 Thread jitendra gupta
hello
here is my code for sending the mail, using this code email is going
'CODE
''
import smtplib
from time import strftime
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.Utils import COMMASPACE, formatdate


# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = " is sending the mail"
msg['From'] = '[email protected] '
msg['Date'] = formatdate(localtime=True)
msg['To'] = '[email protected]'

# Create the body of the message (a plain-text and an HTML version).
#text = "jitendra kya huy a!\nHow are you?\nHere is the link you
wanted:\nhttp://www.python.org";
html = """\

  
  
Hi!
   How are you?
   This mail is send by wjitenrda
   Here is the http://www.python.org";>link you wanted.

  

"""

part2 = MIMEText(html, 'html')


msg.attach(part2)

# Send the message via local SMTP server.
s = smtplib.SMTP('smtp.myprivatedomain.com ')
s.login("user","password")
s.sendmail(msg['From'], msg['To'], msg.as_string())
s.close()
'CODE  END
 
''
using this code i am able to send the email , but problem is
when i am changing
msg['To'] = "[email protected]"
some wrong email then i am getting back failure notice in my inbox, which i
dont want..
is there any way so that i can identify wrong email during the run time
(when i am sending  the email)
--
http://mail.python.org/mailman/listinfo/python-list


Re: NEWB: dividing numbers

2009-03-08 Thread jitendra gupta
try any one 1)
>>>from __future__ import division
>>>2/3 -1/3
0.1

2)
>>>x = 2/3.0
>>>x - 1/3.0
0.1


On Mon, Mar 9, 2009 at 9:33 AM, Daniel Dalton  wrote:

> Hi,
>
> On Mon, Mar 09, 2009 at 12:08:16AM +0100, Lo wrote:
> > I just tried python first time.
> >
> > 2/3
> >
> > the result is zero
>
> That's because your dividing an int by an int to an int. The definition
> of an int is a "whole number". So just use floating point I think it's
> called, this should work, and does just tested with the python
> interactive shell:
> 2.0/3
>
> Cheers,
> Daniel.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Behavior of default parameter in a function

2010-03-11 Thread jitendra gupta
def foo(x = [0]):
x[0] = x[0] + 1
return x[0]

def soo(x = None):
if x is None:
x = [0]
x[0] = x[0] + 1
return x[0]

>>> foo()
1
>>>foo()  #See the behavior incremented by one
2
>>>foo([1]) # but here based on given number
2
>>>foo()
3
>>>foo([1])
2
>>>foo()
4

>>>soo()
1
>>>soo()
1
>>>soo([1])
2
>>>soo()
1

Why foo() is incremented by 1 always when we are not passing any argument,
 but this is not happening in soo() case, In which scenario we will use
these type of  function.'

Thanks
Jitendra Kumar
-- 
http://mail.python.org/mailman/listinfo/python-list