[Tutor] (no subject)

2015-06-10 Thread rakesh sharma

I have come across this syntax in python. Embedding for loop in []. How far can 
things be stretched using this [].
l = [1, 2, 3, 4, 5]
q = [i*2 for i in l]
print qthanksrakesh   
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Using lambda

2015-08-23 Thread rakesh sharma
I am beginner in pythonI see the use of lambda has been for really simple ones 
as in the numerous examples over the net.Why cant we use lambda in another one 
like g = lambda x: (lambda y: y + 1) + 1when I am able to do that in two lines
h = lambda x: x + 1>>> h(12)13y = lambda x: h(x) + 1>>> y(1)3

thanksrakesh  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Private members?

2016-02-26 Thread rakesh sharma
I believe in Python there are no private public concept. All are public by 
default

Sent from Outlook Mobile



On Fri, Feb 26, 2016 at 12:04 AM -0800, "kay Cee" 
mailto:une...@gmail.com>> wrote:

Say I have a basic Circle class, for example:

class Circle:
def __init__(self, radius):
self.__radius = radius

Does adding the double underscore make this member directly inaccessible to 
children of the Circle class?

Also, I'd like to know if there are any side effects to programming classes 
this way?


Sent from my iPhone
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Help regarding reg exp.

2016-10-05 Thread rakesh sharma
Hi all

I have a string of pattern ({A,BC},{(A,B),(B,C)(C,A)}. I want to extract the 
inner brackets {A,B,C} etc. Please help. I have tried various methods of re to 
no avail.


Get Outlook for Android
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] good django book?

2014-02-07 Thread rakesh sharma
Hi Alex,
>From my experience, though in windows env, there is considerable amount of 
>difference in the way both the version gets implemented
thanks,rakesh

> From: eryk...@gmail.com
> Date: Fri, 7 Feb 2014 22:43:55 -0500
> To: aklei...@sonic.net
> CC: tutor@python.org
> Subject: Re: [Tutor] good django book?
> 
> On Fri, Feb 7, 2014 at 8:02 PM, Alex Kleider  wrote:
> > It might be worth pointing out that the version of django that comes with
> > Debian/Ubuntu is
> > Version: 1.3.1-4ubuntu1
> > so worrying about having a text that describes 1.6 vs 1.4 may not be all
> > that important.
> >
> > Comments?
> 
> Debian stable currently supports Django 1.4. Ubuntu's upcoming LTS
> release supports Django 1.6.
> 
> Debian python-django
> Squeeze (oldstable):  1.2.3-3
> Wheezy  (stable): 1.4.5-1
> Jessie  (testing):1.6.1-2
> 
> Oldstable gets security updates for a year, so Squeeze EOL should be
> in May 2014. Jessie enters feature freeze in Nov 2014, but there's no
> release date as of yet.
> 
> Ubuntu python-django (EOL)
> Lucid:   1.1.1-2 (2015-04)
> Precise: 1.3.1-4 (2017-04)
> Quantal: 1.4.1-2 (2014-04)
> Saucy:   1.5.4-1 (2014-07)
> Trusty:  1.6.1-2
> 
> Trusty will be released in Apr 2014.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] learning recursion

2014-02-07 Thread rakesh sharma
Hi
Shouldn't your code be like this
def fib(n): if n==0:return 0else:   return 
n + fib(n-1)
this works
>>> for i in range(4):  print fib(i)
0136>>> 
> To: tutor@python.org
> From: da...@davea.name
> Date: Thu, 6 Feb 2014 18:06:41 -0500
> Subject: Re: [Tutor] learning recursion
> 
>  Denis Heidtmann  Wrote in message:
> >
> > 
> Please post in text, not html. Your posting program loses the
>  indentation in the text view, which is what most people
>  see.
> 
> Code:
> def fib2(n):
>   if n==1:
>   return 1
> 
>   elif n==2:
>   return 1
>   else:
>   return fib2(n-2) +fib2(n-1)
> 
> That code doesn't do anything reasonable for zero or negative
>  values.  Probably what you want is
> 
> if n==0:
> return 0
> elif n <3:
> return 1
> else:
> 
> It would probably be technically correct to raise an exception for
>  n < 1, because fibonacci didn't define earlier values. But it's
>  apparently acceptable to return zero for the zero
>  case.
> 
> 
> 
> 
> -- 
> DaveA
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] learning recursion

2014-02-08 Thread rakesh sharma
Hi
I guess I need to revisit my maths lessons.Thank you for correcting me. 
thanks,rakesh

> From: d...@hashcollision.org
> Date: Sat, 8 Feb 2014 00:20:19 -0800
> Subject: Re: [Tutor] learning recursion
> To: rakeshsharm...@hotmail.com
> CC: da...@davea.name; tutor@python.org
> 
> On Fri, Feb 7, 2014 at 9:05 PM, rakesh sharma
>  wrote:
> > Hi
> >
> > Shouldn't your code be like this
> >
> > def fib(n):
> > if n==0:
> > return 0
> > else:
> > return n + fib(n-1)
> 
> 
> Hi Rakesh,
> 
> Unfortunately, no, because this computes a slightly different
> function: the triangular numbers!  :P
> 
> 
> That is, your function above is an implementation for the sum:
> 
> 0 + 1 + 2 + ... + n
> 
> It's also known as a "Gauss sum".
> 
> 
> ##
> 
> [Tangent ahead.  Skip if you're not interested.]
> 
> As a very tangent note, it's good for us programmers to know about
> this function, because it shows up in some common places.  For
> example, it occurs when we try to figure out approximately how long it
> takes to concatenate a bunch of strings in a naive way.
> 
> Imagine the following artificial scenario:
> 
> #
> long_string = ""
> for n in range(1000):
> long_string = long_string + "X"
> #
> 
> where we're building up a large string with repeated concatenations.
> 
> Does this look bad to you?  It should!  The string concatenation
> operation takes time that's proportional to the size of the string
> we're building up.  If we do the above, with _repeated_ string
> concatenation, going through the whole loop will cost, altogether,
> something on the order of:
> 
> 0 + 1 + 2 + ... + 1000
> 
> elementary operations, representing the first, second, ... and
> thousandth time through that loop.
> 
> And if you know your Gauss sum, this sum can be quickly computed
> without having to do each individual addition:
> 
> 0 + 1 + 2 + ... + 1000
> = (1000 * 1001) / 2
> = 500500
> 
> which is a fairly big number.
> 
> In general:
> 
> 0 + 1 + 2 + ... + n
> = n * (n+1) / 2
> 
> In practice, this means for us programmers that if we're going to
> build up a large string in parts, doing repeated string concatenation
> is not the right approach as it means we're doing things in quadratic
> time.  It's better to build up a list of strings, and then do the
> concatenation all at once, avoiding the repeating rebuilding of a
> larger and larger string:
> 
> #
> long_string_chunks = []
> for n in range(1000):
> long_string_chunks.append("X")
> long_string = "".join(long_string_chunks)
> #
> 
> where the "".join(...) part, having been implemented well, and knowing
> all the long_string_chunk elements, can do the string concatenation in
> one single, efficient pass.
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] learning recursion

2014-02-08 Thread rakesh sharma
I got my definition wrong
the code should be more like this
def fib(n): if n==0:return  elif n==1:  return 
1elif n==2:  return 1else:   return 
fib(n-2) + fib(n-1)
thanks,rakesh
> Date: Fri, 7 Feb 2014 21:40:49 -0800
> Subject: Re: [Tutor] learning recursion
> From: denis.heidtm...@gmail.com
> To: rakeshsharm...@hotmail.com
> CC: da...@davea.name; tutor@python.org
> 
> On Fri, Feb 7, 2014 at 9:05 PM, rakesh sharma
>  wrote:
> > Hi
> >
> > Shouldn't your code be like this
> >
> > def fib(n):
> > if n==0:
> > return 0
> > else:
> > return n + fib(n-1)
> >
> > this works
> >
> >>>> for i in range(4):
> > print fib(i)
> >
> > 0
> > 1
> > 3
> > 6
> >>>>
> 
> interesting, but the Fibonacci sequence is 1,1,2,3,5,8,13,...
> 
> -Denis H.
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trace / profile every function with inputs

2014-02-10 Thread rakesh sharma
Hi,
Have tried inspect module in python.See this code
def foo():  print inspect.stack()[0][3]
>>> foo()foo>>> 
this shall meet your purpose I believe
thanks,rakesh
> From: r.cziv...@research.gla.ac.uk
> To: tutor@python.org
> Date: Fri, 7 Feb 2014 16:07:58 +
> Subject: [Tutor] trace / profile every function with inputs
> 
> Hi All,
> 
> I am struggling with a "simple" problem: I would like to print out every 
> function that is being executed while my Python program is running. I can not 
> modify the Python programs that I would like to profile.
> 
> Let me give an example. A program contains a function and a call like this:
> 
> def foo(x):
>   y = math.cos(x)
>   time.sleep(y+1)
>   return x * 50
> 
> print foo(100)
> 
> I would like to retrieve an execution trace that shows me each function 
> called (with the value or hash of the function arguments). According to the 
> example, I am looking for a way to extract something similar:
> 
> foo(100)
> math.cos(100)
> time.sleep(0.87)
> 
> Things I have tried with only partial success:
> - trace: couldn't get the function names in some cases
> - profile / cProfile: no information about the arguments
> 
> Could you suggest me a way of doing this?
> 
> Thanks,
> Richard
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Upload a file using python

2014-02-16 Thread rakesh sharma
Greetings!!
Hi ,

I need to upload some file into a website. Its ajax based and so I managed to 
do using selenium.But I feel if i can use the http methods without involving 
any UI level automation things would be better.I have tried 'requests' library 
for this. Can't get how to upload a file. I performed it using post method. But 
dint get the required result.The uploaded file dint appear in the site. 
Any help anyone?
thanks,rakesh ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Upload a file using python

2014-02-17 Thread rakesh sharma
Greetings!!
Hi Alan,
The error code was that of success. 200.Donno if the site supports a post 
method. It doesn't but is there any other way of automating the process.The 
issue of chrome 32 with selenium webdriver has stalled the show for me. Hence i 
had to fend for some other ways.
thanks,rakesh

> To: tutor@python.org
> From: alan.ga...@btinternet.com
> Date: Sun, 16 Feb 2014 15:17:52 +
> Subject: Re: [Tutor] Upload a file using python
> 
> On 16/02/14 09:15, rakesh sharma wrote:
> 
> > But I feel if i can use the http methods without involving any UI level
> > automation things would be better.
> 
> To use http the server at the other end needs to know what you are 
> trying to do. Given it already publishes an Ajax interface I'd have 
> thought it was unlikely to also have a raw http interface for file uploads.
> 
> > file. I performed it using post method. But dint get the required result.
> > The uploaded file dint appear in the site.
> 
> Does the server have a page that accepts post requests to upload files?
> If not it won't recognize your post request and possibly just ignore
> it or hopefully send you an http error back. Did you check the http 
> error code returned?
> 
> HTH
> -- 
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.flickr.com/photos/alangauldphotos
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Creating a pojo in python

2015-02-08 Thread rakesh sharma
How can one create a POJO in python.I mean a class like this
class A {   private a;   private b;   public getA() {   return a;   }   
public getB() {  return b   }}
I tried creating class in python but the variables were accessible as public 
data members.
Any help? 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2015-02-19 Thread rakesh sharma
Greetings !!
Hi all,
what the meaning of the line at the start of the python file
__author__ = "user"

thanks in advancerakesh   
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Error with sqlalchemy

2017-08-01 Thread rakesh sharma
Hi All


I am getting an error in python. Its a flask app that I am doing

I am getting the error

TypeError: utf_8_decode() argument 1 must be string or buffer, not long

at this point in the code

ship_schedules = ShipSchedule.query.all()

The schema definition is like that I gave below, there is no mismatch between 
the schema and the table definition in the mysql DB.

class ShipSchedule(Base):

__tablename__ = 'ship_schedule'

vessel_imo_no = Column(Integer, primary_key=True, nullable=False)
commodity_product_code = Column(String, nullable=False)
port_port_code = Column(String, nullable=False)
cargo_quantity = Column(String, nullable=False)
activity = Column(String, nullable=False)
date_from = Column(Date, nullable=False)
date_to = Column(Date, nullable=False)


"""
Ship schedule schema
"""


class ShipScheduleSchema(Schema):
vessel_imo_no = fields.Int(dump_only=True)
commodity_product_code = fields.Str()
port_port_code = fields.Str()
cargo_quantity = fields.Int()
activity = fields.Str()
date_from = fields.Date()
date_to = fields.Date()

the mysql table defintion is as follows


[cid:e101f2ac-60ca-426a-8e53-01afd9e9414d]


please help on this, do not know the whats causing the issue.

I dint find any good answers in stackoverflow as all points to schema mismatch

thanks

rakesh
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor