[Tutor] File extension against File content

2019-05-31 Thread Sunil Tech
Hi Tutor,

Is there any way that I can actually programmatically compare the file
extension with its content?

This is because we can manually save the file in one extension and later
rename the file extension to some other.

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


Re: [Tutor] Trouble in dealing with special characters.

2018-12-07 Thread Sunil Tech
Hi Alan,

I am using Python 2.7.8
>>> tx = "MOUNTAIN VIEW WOMEN’S HEALTH CLINIC"
>>> tx.decode()
Traceback (most recent call last):
  File "", line 1, in 
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 19:
ordinal not in range(128)

How to know whether in a given string(sentence) is there any that is not
ASCII character and how to replace?

On Fri, Dec 7, 2018 at 2:01 PM Alan Gauld via Tutor 
wrote:

> On 07/12/2018 07:58, Sunil Tech wrote:
>
> > I have a trouble with dealing with special characters in Python Below is
> > the sentence with a special character(apostrophe) "MOUNTAIN VIEW WOMEN’S
> > HEALTH CLINIC" with actually should be "MOUNTAIN VIEW WOMEN'S HEALTH
> CLINIC
> > ".
>
> How do you define "special characters"?
> There is nothing special about the apostraphe. It is just as
> valid a character as all the other characters.
> What makes it special to you?
>
> > Please help, how to identify these kinds of special characters and
> replace
> > them with appropriate ASCII?
>
> What is appropriate ASCII?
> ASCII only has 127 characters.
> Unicode has thousands of characters.
> How do you want to map a unicode character into ASCII?
> There are lots of options but we can't tell what you
> think is appropriate.
>
> Finally, character handling changed between Python 2 and 3
> (where unicode became the default), so the solution will
> likely depend on the Python version you are using.
> Please tell us which.
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> 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] Trouble in dealing with special characters.

2018-12-07 Thread Sunil Tech
Hi Tutor,

I have a trouble with dealing with special characters in Python Below is
the sentence with a special character(apostrophe) "MOUNTAIN VIEW WOMEN’S
HEALTH CLINIC" with actually should be "MOUNTAIN VIEW WOMEN'S HEALTH CLINIC
".

Please help, how to identify these kinds of special characters and replace
them with appropriate ASCII?

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


[Tutor] Python Memory Allocation -- deep learning

2018-07-30 Thread Sunil Tech
Hi Team,

I am investigating how the memory allocation happens in Python
For Eg:
*Case 1:*

>>> a = 10
>>> b = 10
>>> c = 10
>>> id(a), id(b), id(c)
(140621897573616, 140621897573616, 140621897573616)
>>> a += 1
>>> id(a)
140621897573592


*Case 2:*

>>> x = 500
>>> y = 500
>>> id(x)
4338740848
>>> id(y)
4338741040


*Case 3:*

>>> s1 = 'hello'
>>> s2 = 'hello'
>>> id(s1), id(s2)
(4454725888, 4454725888)
>>> s1 == s2
True
>>> s1 is s2
True
>>> s3 = 'hello, world!'
>>> s4 = 'hello, world!'
>>> id(s3), id(s4)
(4454721608, 4454721664)
>>> s3 == s4
True
>>> s3 is s4
False

Python memory allocation is varying in all these use cases. Please help me
understand.

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


Re: [Tutor] Manipulating Dictionary values

2016-12-26 Thread Sunil Tech
Thank you Steven D'Aprano and Alan Gauld.

On Mon, Dec 26, 2016 at 4:41 PM, Alan Gauld via Tutor 
wrote:

> On 26/12/16 08:03, Sunil Tech wrote:
> > Hi Team,
> >
> > Dictionary is like
> >
> > a = {'a': 'New', 'b': 'Two', 'l': [{'k': 'test', 'm': 'again'}, {'k':
> > 'test', 'm': 'again'}]}
> >
> > I am trying to modify a value in the dictionary value at a['l']
>
> So make life easy for yourself and get rid of the outer dictionary
> and use the python prompt to experiment:
>
> >>> L = [{'k': 'test', 'm': 'again'}, {'k': 'test', 'm': 'again'}]
> >>> [{'k':d['k'],'m':'replaced'} for d in L]
> [{'k': 'test', 'm': 'replaced'}, {'k': 'test', 'm': 'replaced'}]
> >>>
>
> But that's not very general, you really should have a generator
> for the dictionary that has a conditional expression within to
> replace the m. But that means having a generator within a
> comprehension inside a dictionary access.
>
> It's all getting a bit ugly and overly complex and our goal as
> programmers is to write clear, easily maintainable code, so
> this is probably a bad idea.
>
> Better to unroll into an explicit loop and make it obvious
> what you are doing.
>
> for d in a['l']: d['m'] = 'replaced'
>
> Isn't that clearer?
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> 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


Re: [Tutor] Manipulating Dictionary values

2016-12-26 Thread Sunil Tech
​​
Can this be achievable in one liner?

On Mon, Dec 26, 2016 at 1:33 PM, Sunil Tech  wrote:
>
> Hi Team,
>
> Dictionary is like
>
> a = {'a': 'New', 'b': 'Two', 'l': [{'k': 'test', 'm': 'again'}, {'k':
'test', 'm': 'again'}]}
>
> I am trying to modify a value in the dictionary value at a['l'] & at 'm'
> expecting it to be
>
> a = {'a': 'New', 'b': 'Two', 'l': [{'k': 'test', 'm': 'replaced'}, {'k':
'test', 'm': 'replaced'}]}
>
> for which I tried to do using list comprehension
>
> >>> a['l'] = [i['m'].replace('again', 'replaced') for i in a['l']]
> >>> a
> {'a': 'New', 'b': 'Two', 'l': ['replaced', 'replaced']}
>
> Any help will be appreciated.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Manipulating Dictionary values

2016-12-26 Thread Sunil Tech
Hi Team,

Dictionary is like

a = {'a': 'New', 'b': 'Two', 'l': [{'k': 'test', 'm': 'again'}, {'k':
'test', 'm': 'again'}]}

I am trying to modify a value in the dictionary value at a['l'] & at 'm'
expecting it to be

a = {'a': 'New', 'b': 'Two', 'l': [{'k': 'test', 'm': 'replaced'}, {'k':
'test', 'm': 'replaced'}]}

for which I tried to do using list comprehension

>>> a['l'] = [i['m'].replace('again', 'replaced') for i in a['l']]
>>> a
{'a': 'New', 'b': 'Two', 'l': ['replaced', 'replaced']}

Any help will be appreciated.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Optimize the code - removing the multiple IF conditions

2015-12-22 Thread Sunil Tech
My heartly thanks to Steven D'Aprano, Alan Gauld and Peter Otten
​ for addressing this.​

I would go with Steven D'Aprano
​ point​
 and will take Alan Gauld inputs.
Thanks once again.


On Mon, Dec 21, 2015 at 9:56 PM, Alan Gauld 
wrote:

> On 21/12/15 12:22, Sunil Tech wrote:
>
> > class OptIf(object):
> > """docstring for OptIf"""
>
> This does not look like a useful class, it should probably
> just be a function. Are you really going to have multiple
> instances?
>
> > def opt_me(self, ext):
> > if ext == 'CM':
> > rec = self.call_cm(cm, ad)
> > if ext == 'MM':
> > rec = self.call_mm(mm, ax)
> > if ext == 'DM':
> > rec = self.call_dm(dm, md)
> > return rec
>
> These should probably be an if/elif chain rather
> than multiple if options (no risk of multiple
> operations).
>
> Without knowing more about what this is doing and what the
> various parameters represent it's hard to be sure how best
> to "optimise" it. Bear in mind too that optimising may mean
> improving readability and the if statements may be more
> readable and maintainable than any dictionary lookup
> would be.
>
> > def call_cm(cm, ad):
> > def call_mm(mm, ax):
> > def call_dm(dm, md):
>
> As methods they should have a self parameter.
>
> But these look suspiciously like the same method
> with different names. The first parameter looks
> like it might be a size value. (But I've no idea
> what the second is supposed to be.)
>
> Could this be a single function which incorporates
> a scaling factor?
>
> > med_map = {'CM': call_cm, 'MM': call_mm, 'DM': call_dm}
> > but I am not able to pass the arguments.
>
> They all take two arguments so you can pass those in
> if the types are consistent.
>
> result = med_map[unit](arg1,arg2)
>
> Your problems start if the parameters are all
> different types. If that's the case you are probably
> better sticking with the if chain. Or maybe creating
> three real classes that can be instantiated as needed
> and use polymorphism to avoid the if statements.
>
> But without any more detail on what's really going on
> I am just making wild guesses.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> 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] Optimize the code - removing the multiple IF conditions

2015-12-21 Thread Sunil Tech
Hi,

I Have a code..


class OptIf(object):
"""docstring for OptIf"""

def opt_me(self, ext):
if ext == 'CM':
rec = self.call_cm(cm, ad)
if ext == 'MM':
rec = self.call_mm(mm, ax)
if ext == 'DM':
rec = self.call_dm(dm, md)
return rec

def call_cm(cm, ad):
pass

def call_mm(mm, ax):
pass

def call_dm(dm, md):
pass


I want to optimize the code by removing the if conditions in the opt_me
method,
I tried with few things making a dictionary of key as the ext and the value
as the method that to be called.

med_map = {'CM': call_cm, 'MM': call_mm, 'DM': call_dm}
but I am not able to pass the arguments.

can you please help or suggest the other way?


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


Re: [Tutor] Need to call a custom/magic method on calling of every Class methods

2015-12-17 Thread Sunil Tech
Oh!

Thank you so much Steven for the reply.

On Thu, Dec 17, 2015 at 7:03 PM, Steven D'Aprano 
wrote:

> On Thu, Dec 17, 2015 at 05:18:26PM +0530, Sunil Tech wrote:
> > Hi Tutor,
> >
> > I am searching for any magic method/or any method that calls on every
> > calling of the Class methods.
> [...]
> > Is there any magic method that is auto called on every call of these
> Class
> > Methods?
>
> No, not really, but you can get *close* to what you want. You can't
> intercept *calling* the methods, but you can intercept the attribute
> lookup:
>
>
> class A(object):
> def __getattribute__(self, name):
> attr = super(A, self).__getattribute__(name)
> if callable(attr):
> print(name)
> return attr
> def one(self):
> return 1
> def two(self):
> return 2
>
>
> But beware that this will slow down all attribute access.
>
> This is possibly the simplest solution. Perhaps a better solution would
> be to create a custom Method descriptor, and then modify the class to
> use this descriptor instead of standard methods. But this is much
> more work.
>
>
>
> --
> Steve
> ___
> 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] Need to call a custom/magic method on calling of every Class methods

2015-12-17 Thread Sunil Tech
Hi Tutor,

I am searching for any magic method/or any method that calls on every
calling of the Class methods.

for example:

Class A(object):
def one(self):
return

def two(self):
return

I need a method that prints which method is called in this class.
I am aware of __call__() but this is called only once when the Class is
called
and decorators. This is need to placed on every method.

c = A()
c()  # __call__ method is called.

Is there any magic method that is auto called on every call of these Class
Methods?



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


Re: [Tutor] super and __init__ methods

2015-11-26 Thread Sunil Tech
Thanks I got it.

class Cain(Adam):
"""docstring for Cain"""
def __init__(self, age, *args):
super(Cain, self).__init__(*args)
self.age = age


a = Adam('Eve')
c = Cain(12, 'Eve')
print a.name, c.age, c.name
>>> Eve 12 Eve


On Fri, Nov 27, 2015 at 12:44 PM, Sunil Tech 
wrote:

> class Adam(object):
> """docstring for Adam"""
> def __init__(self, name):
> self.name = name
>
>
> class Cain(Adam):
> """docstring for Cain"""
> def __init__(self, age, *args):
> super(Cain, self).__init__(age, *args)
> self.age = age
>
>
> a = Adam('Eve')
> c = Cain(12)
> print a.name, c.age, c.name
> >>> Eve 12 12
>
> May i know why c.name is 12?
> I am expecting Eve.
>
> Help me to understand.
>
>
> Thanks,
> Sunil. G
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] super and __init__ methods

2015-11-26 Thread Sunil Tech
class Adam(object):
"""docstring for Adam"""
def __init__(self, name):
self.name = name


class Cain(Adam):
"""docstring for Cain"""
def __init__(self, age, *args):
super(Cain, self).__init__(age, *args)
self.age = age


a = Adam('Eve')
c = Cain(12)
print a.name, c.age, c.name
>>> Eve 12 12

May i know why c.name is 12?
I am expecting Eve.

Help me to understand.


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


[Tutor] Unpack from list

2015-07-13 Thread Sunil Tech
Hi Tutor,


[a,b,c] = [1,2]
this will give
Traceback (most recent call last):
  File "", line 1, in 
ValueError: need more than 2 values to unpack

But is there any chance, if there are 3 values on left hand side and 2
values on right side, to add an empty value to the left side dynamically?

there can be multiple elements to unpack depending on what is expected on
left side.
Like in methods there can be optional parameters, if the values is not
passed, optional values will take what is been declared.

def optal(a,b,c=''):

"""

c - is option

"""

​Thanks,
Sunil. G
​
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Docstring

2015-06-09 Thread Sunil Tech
Thanks Alan Gauld

On Mon, Jun 8, 2015 at 9:27 PM, Alan Gauld 
wrote:

> On 08/06/15 10:34, Sunil Tech wrote:
>
>  what is the standard way of using docstrings?
>>
>
> As Steven said there are several "standards".
>
> Yet another option is to use the format required
> by doctest. For your example:
>
> def test(x):
>   """
>   A dummy method
>   >>> test(5)
>   True
>   >>> test(-5)
>   False
>   """
>
> Or whatever test cases make sense.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> 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


Re: [Tutor] Docstring

2015-06-08 Thread Sunil Tech
Thank you Steven D'Aprano

On Mon, Jun 8, 2015 at 4:04 PM, Steven D'Aprano  wrote:

> On Mon, Jun 08, 2015 at 03:04:05PM +0530, Sunil Tech wrote:
> > Hi Team,
> >
> > what is the standard way of using docstrings?
>
> There isn't one standard way of using docstrings. Different systems use
> different conventions.
>
> The conventions for the Python standard library are described here:
>
> https://www.python.org/dev/peps/pep-0257/
>
> The conventions used by Google are here:
>
> http://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Comments
>
>
> Epydoc uses Javadoc conventions:
>
>"""This is a javadoc style.
>
>@param param1: this is a first param
>@param param2: this is a second param
>@return: this is a description of what is returned
>@raise keyError: raises an exception
>"""
>
>
> Sphinx uses ReST conventions:
>
>"""This is a ReST style.
>
>:param param1: this is a first param
>:param param2: this is a second param
>:returns: this is a description of what is returned
>:raises keyError: raises an exception
>"""
>
> and also understands Google's conventions:
>
> """This is Google's style.
>
> Parameters:
> param1 - this is the first param
> param2 - this is a second param
>
> Returns:
> This is a description of what is returned
>
> Raises:
> KeyError - raises an exception
> """
>
>
> Numpy also has their own custom format, which apparently
> Sphinx also understands. Pycco uses Markdown rather than ReST. There's
> also Doxygen, but I don't know what it uses. So that's *at least* five
> different conventions.
>
>
>
> > for example (Sphinx)
> > def test(x):
> > """
> > A dummy method
> > Args:
> > x (int): first argument
> > Returns:
> > "true or false"
> > """
> >
> > and if the method has no arguments?
> > how should be the docstring?
>
>
> Just leave it out:
>
>
> """A dummy method.
>
> Returns:
> "true or false"
> """
>
>
>
> --
> Steve
> ___
> 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] Docstring

2015-06-08 Thread Sunil Tech
Hi Team,

what is the standard way of using docstrings?
for example (Sphinx)
def test(x):
"""
A dummy method
Args:
x (int): first argument
Returns:
"true or false"
"""

and if the method has no arguments?
how should be the docstring?


Thanks & Regards,
Sunil. G
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Decode and Encode

2015-01-28 Thread Sunil Tech
Thank you for all your replies​​


On Wed, Jan 28, 2015 at 4:56 PM, Steven D'Aprano 
wrote:

> On Wed, Jan 28, 2015 at 03:05:58PM +0530, Sunil Tech wrote:
> > Hi All,
> >
> > When i copied a text from web and pasted in the python-terminal, it
> > automatically coverted into unicode(i suppose)
> >
> > can anyone tell me how it does?
> > Eg:
> > >>> p = "你好"
> > >>> p
> > '\xe4\xbd\xa0\xe5\xa5\xbd'
>
> It is hard to tell exactly, since we cannot see what p is supposed to
> be. I am predicting that you are using Python 2.7, which uses
> byte-strings by default, not Unicode text-strings.
>
> To really answer your question correctly, we need to know the operating
> system and which terminal you are using, and the terminal's encoding. I
> will guess a Linux system, with UTF-8 encoding in the terminal.
>
> So, when you paste some Unicode text into the terminal, the terminal
> receives the UTF-8 bytes, and displays the characters:
>
> 你好
>
> On my system, they display like boxes, but I expect that they are:
>
> CJK UNIFIED IDEOGRAPH-4F60
> CJK UNIFIED IDEOGRAPH-597D
>
> But, because this is Python 2, and you used byte-strings "" instead of
> Unicode strings u"", Python sees the raw UTF-8 bytes.
>
> py> s = u'你好'  # Note this is a Unicode string u'...'
> py> import unicodedata
> py> for c in s:
> ... print unicodedata.name(c)
> ...
> CJK UNIFIED IDEOGRAPH-4F60
> CJK UNIFIED IDEOGRAPH-597D
> py> s.encode('UTF-8')
> '\xe4\xbd\xa0\xe5\xa5\xbd'
>
> which matches your results.
>
> Likewise for this example:
>
> py> s = u'ªîV'  # make sure to use Unicode u'...'
> py> for c in s:
> ... print unicodedata.name(c)
> ...
> FEMININE ORDINAL INDICATOR
> LATIN SMALL LETTER I WITH CIRCUMFLEX
> LATIN CAPITAL LETTER V
> py> s.encode('utf8')
> '\xc2\xaa\xc3\xaeV'
>
>
> which matches yours:
>
> > >>> o = 'ªîV'
> > >>> o
> > '\xc2\xaa\xc3\xaeV'
>
>
> Obviously all this is confusing and harmful. In Python 3, the interpeter
> defaults to Unicode text strings, so that this issue goes away.
>
>
> --
> Steve
> ___
> 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] Decode and Encode

2015-01-28 Thread Sunil Tech
Hi All,

When i copied a text from web and pasted in the python-terminal, it
automatically coverted into unicode(i suppose)

can anyone tell me how it does?
Eg:
>>> p = "你好"
>>> p
'\xe4\xbd\xa0\xe5\xa5\xbd'
>>> o = 'ªîV'
>>> o
'\xc2\xaa\xc3\xaeV'
>>>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] bubble sort function

2014-11-26 Thread Sunil Tech
Thank you Alan for explanation

That's what the bit inside the loop does.
> It checks whether the input string is a digit (specifically a decimal
> digit).
> If it is a digit it returns the result as an integer
> otherwise it spits out an error and goes round the loop again.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] bubble sort function

2014-11-26 Thread Sunil Tech
​Thank you Dave​

On Wed, Nov 26, 2014 at 5:23 PM, Dave Angel  wrote:

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


Re: [Tutor] bubble sort function

2014-11-26 Thread Sunil Tech
Thank you Alan. But a question here, how would it understand that the given
input is valid?



The while loop makes it keep on asking until a valid input is
received. Without the while loop it would only ask once and
either return None or a digit.



On Wed, Nov 26, 2014 at 3:46 PM, Alan Gauld 
wrote:

> On 26/11/14 09:57, Sunil Tech wrote:
>
>> Hi Danny,
>>
>> Curious to the use the need of using while True in the given example of
>> ask_for_a_digit().
>>
>>
>> On Mon, Nov 17, 2014 at 9:57 AM, Danny Yoo > <mailto:d...@hashcollision.org>> wrote:
>>
>> > def ask_for_a_digit():
>> > while True:
>> > digit = raw_input("Give me a digit between 0 and 9.")
>> > if digit not in "0123456789":
>> > print "You didn't give me a digit.  Try again."
>> > else:
>> > return int(digit)
>>
>
> The while loop makes it keep on asking until a valid input is
> received. Without the while loop it would only ask once and
> either return None or a digit.
>
> HTH
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> 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


Re: [Tutor] no longer need this tutor

2014-11-26 Thread Sunil Tech
Hi,

If you don't need.
You can anytime simply go to the link which is mentioned (as a footer in
the email) and unsubscribe.
rather posting this message to the tutor.

On Wed, Nov 26, 2014 at 2:59 PM, moemedi baboile <
moemedibabo...@yahoo.com.dmarc.invalid> wrote:

> I want thank you guys for helping me out with python programming.I
> achieved the best out of this and now am on the next stage of programming,
> I now don't need this tutor any more...thank you once again.
>
> ___
> 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] bubble sort function

2014-11-26 Thread Sunil Tech
Hi Danny,

Curious to the use the need of using while True in the given example of
ask_for_a_digit().


On Mon, Nov 17, 2014 at 9:57 AM, Danny Yoo  wrote:

> > def ask_for_a_digit():
> > while True:
> > digit = raw_input("Give me a digit between 0 and 9.")
> > if digit not in "0123456789":
> > print "You didn't give me a digit.  Try again."
> > else:
> > return int(digit)
>
>
> Ooops.  I made a mistake.  ask_for_a_digit() is not technically quite
> right, because I forgot that when we're doing the expression:
>
> digit not in "0123456789"
>
> that this is technically checking that the left side isn't a substring
> of the right side.  That's not what I wanted: I intended to check for
> element inclusion instead.  So there are certain inputs where the
> buggy ask_for_a_digit() won't return an integer with a single digit.
>
> Here's one possible correction:
>
> ###
> def ask_for_a_digit():
> while True:
> digit = raw_input("Give me a digit between 0 and 9.")
> if len(digit) != 1 or digit not in "0123456789":
> print "You didn't give me a digit.  Try again."
> else:
> return int(digit)
> ###
>
>
> My apologies for not catching the bug sooner.
> ___
> 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] Question on List of Dict

2014-09-19 Thread Sunil Tech
Thank you Peter Otten,

actually i should study about the collections and defaultdict like how and
where these can be used and its advantage.



On Fri, Sep 19, 2014 at 5:59 PM, Peter Otten <__pete...@web.de> wrote:

> Sunil Tech wrote:
>
> > Danny i did it like this
> >
> > result_dict = {}
> > for i in tes:
> > if i['a'] in result_dict:
> > temp = result_dict[i['a']]
> > temp['b'].append(i['b'])
> > temp['c'].append(i['c'])
> > temp['a'] = i['a']
> > result_dict[i['a']] = temp
> > else:
> > result_dict[i['a']] = {
> > 'b': [i['b']],
> > 'c': [i['c']],
> > 'a': i['a']}
> > pprint.pprint(result_dict.values())
> >
> > result is
> >
> > [{'a': 1, 'b': ['this', 'is', 'sentence'], 'c': [221, 875, 874]},
> >  {'a': 2, 'b': ['this', 'another', 'word'], 'c': [215, 754, 745]}]
> >
> > any can one improve this method in terms of performance, etc..
>
> What you have is a good solution; the most important part performance-wise
> is that you collect records with the same `a` value in a dict.
>
> For reference here's my two-pass solution to the problem as originally
> specified:
>
> bc = collections.defaultdict(lambda: ([], []))
>
> for rec in tes:
> b, c = bc[rec["a"]]
> b.append(rec["b"])
> c.append(rec["c"])
>
> result = [{"a": a,
>"b": ", ".join(b),
>"c": ", ".join(map(str, c))}
>   for a, (b, c) in bc.items()]
>
> If you are flexible with the result data structure you could omit the
> second
> loop and use bc.items() directly.
>
> ___
> 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] Question on List of Dict

2014-09-19 Thread Sunil Tech
Danny i did it like this

result_dict = {}
for i in tes:
if i['a'] in result_dict:
temp = result_dict[i['a']]
temp['b'].append(i['b'])
temp['c'].append(i['c'])
temp['a'] = i['a']
result_dict[i['a']] = temp
else:
result_dict[i['a']] = {
'b': [i['b']],
'c': [i['c']],
'a': i['a']}
pprint.pprint(result_dict.values())

result is

[{'a': 1, 'b': ['this', 'is', 'sentence'], 'c': [221, 875, 874]},
 {'a': 2, 'b': ['this', 'another', 'word'], 'c': [215, 754, 745]}]

any can one improve this method in terms of performance, etc..

Thanks every one.

On Fri, Sep 19, 2014 at 1:22 PM, Danny Yoo  wrote:

>
> On Sep 19, 2014 12:28 AM, "Danny Yoo"  wrote:
> >
> >
> > >{'a': 2, 'b': 'another', 'c': 754},
> > >{'a': 2, 'b': 'word', 'c': 745}
> > >
> >
> > > if the value of the 'a' is same, then all those other values of the
> dict should be merged/clubbed.
> >
> > Can you write a function that takes two of these and merges them?
> Assume that they have the same 'a'.  Can you write such a function?
>
> Specifically, can you write a function merge_two() such that:
>
> merge_two({''b': 'another', 'c': 754}, {'b': 'word', 'c': 745})
>
> returns the merged dictionary:
>
>{'b' : ['another', 'word'], 'c':[754, 745]}
>
> I'm trying to break the problem into simpler, testable pieces that you can
> solve.  The problem as described is large enough that I would not dare
> trying to solve it all at once.  If you have merge_two(), them you are much
> closer to a solution to the whole problem.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question on List of Dict

2014-09-19 Thread Sunil Tech
Danny,
i wrote a method called *merge *below

can you be little clear with an example

I wrote something like this

​​
ids = []
for i in tes:
if i['a'] not in ids:
ids.append(i['a'])
print ids


def merge(ids, tes):
for jj in ids:
txt = ''
for i in tes:
if i['a'] == jj:
txt = txt + ', ' + i['b']
i['b'] = txt
return tes
pprint.pprint(merge(ids, tes))

result is like
[1, 2]

[{'a': 1, 'b': ', this', 'c': 221},
 {'a': 2, 'b': ', this', 'c': 215},
 {'a': 1, 'b': ', this, is', 'c': 875},
 {'a': 1, 'b': ', this, is, sentence', 'c': 874},
 {'a': 2, 'b': ', this, another', 'c': 754},
 {'a': 2, 'b': ', this, another, word', 'c': 745}]


from this result need to take off the other dict so that it'll match the
result_tes = [{'a': 1, 'b': 'this, is, sentence', 'c': '221, 875, 874'},
  {'a': 2, 'b': 'this, another, word', 'c': '215, 754, 744'}]


On Fri, Sep 19, 2014 at 12:58 PM, Danny Yoo  wrote:

>
> >{'a': 2, 'b': 'another', 'c': 754},
> >{'a': 2, 'b': 'word', 'c': 745}
> >
>
> > if the value of the 'a' is same, then all those other values of the dict
> should be merged/clubbed.
>
> Can you write a function that takes two of these and merges them?  Assume
> that they have the same 'a'.  Can you write such a function?
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Question on List of Dict

2014-09-18 Thread Sunil Tech
Hi all,

tes = [{'a': 1, 'b': 'this', 'c': 221},
   {'a': 2, 'b': 'this', 'c': 215},
   {'a': 1, 'b': 'is', 'c': 875},
   {'a': 1, 'b': 'sentence', 'c': 874},
   {'a': 2, 'b': 'another', 'c': 754},
   {'a': 2, 'b': 'word', 'c': 745}]

The above one is  the result form the DB. I am trying to convert it to
something like

result_tes = [{'a': 1, 'b': 'this, is, sentence', 'c': '221, 875, 874'},
  {'a': 2, 'b': 'this, another, word', 'c': '215, 754, 744'}]

if the value of the 'a' is same, then all those other values of the dict
should be merged/clubbed.

I tried, but it became complex and complex.

please can any one help me to get the result.


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


Re: [Tutor] Question on dictionary

2014-09-12 Thread Sunil Tech
Thank you Danny and Joel :)

On Fri, Sep 12, 2014 at 9:51 PM, Joel Goldstick 
wrote:

> On Fri, Sep 12, 2014 at 12:04 PM, Danny Yoo 
> wrote:
> >
> >> i wrote a code like this
> >>
> >> for i in res:
> >> dict = {}
> >> dict['id_desc'] = str(i['id'])+','+str(i['description'])
>
> A minor revision for the right side of above:
>",".join(str(i['id'], str(i['description']))
>
> >> i.update(dict)
> >>
> >> is there any other simple methods to achieve this?
> >>
> >
> > Can you avoid the intermediate "dict" and just assign to i['id_desc']
> > directly?
> >
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
> >
>
>
>
> --
> Joel Goldstick
> http://joelgoldstick.com
> ___
> 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] Question on dictionary

2014-09-12 Thread Sunil Tech
Hi All,

i have a dictionary like

res = [{'description': 'Testo',
  'id': '676',
  'parentOf': True},
{'description': 'Pesto',
  'id': '620',
  'parentOf': False}]

i looking for the result like this

res = [{'description': 'Testo',
  'id': '676',
'id_desc':'676_Testo',
  'parentOf': True},
{'description': 'Pesto',
  'id': '620',
'id_desc':'620_Pesto',
  'parentOf': False}]

to get this result

i wrote a code like this

for i in res:
dict = {}
dict['id_desc'] = str(i['id'])+','+str(i['description'])
i.update(dict)

is there any other simple methods to achieve this?

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


Re: [Tutor] re module

2014-08-19 Thread Sunil Tech
Hey thanks Danny Yoo, Chris “Kwpolska” Warrick, D.V.N Sarma
​.

I will take all your inputs.

Thanks a lot.​


On Fri, Aug 15, 2014 at 3:32 AM, Danny Yoo  wrote:

> On Thu, Aug 14, 2014 at 8:39 AM, D.V.N.Sarma డి.వి.ఎన్.శర్మ
>  wrote:
> > I tested it on IDLE. It works.
>
>
> Hi Sarma,
>
>
> Following up on this one.  I'm pretty sure that:
>
> print re.search("
> is going to print something, but it almost certainly will not do what
> Sunil wants.  See:
>
> https://docs.python.org/2/howto/regex.html#greedy-versus-non-greedy
>
> for why.
> ___
> 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] re module

2014-08-14 Thread Sunil Tech
Hi,

I have string like
stmt = 'Patient name: Upadhyay Shyam  Date of
birth:   08/08/1988 Issue(s) to be
analyzed:  tesNurse Clinical summary:  test1 Date of
injury:   12/14/2013Diagnoses:   723.4 - 300.02 - 298.3
- 780.50 - 724.4 Brachial neuritis or radiculitis nos - Generalized
anxiety disorder - Acute paranoid reaction - Unspecified sleep disturbance
- Thoracic or lumbosacral neuritis or radiculitis, unspecifiedRequester
name:   Demo SpltycdtesttPhone #:   (213)
480-9000Medical records reviewed __ pages of medical and
administrative records were reviewed including:Criteria
used in analysis  Reviewer comments DeterminationBased on the clinical information submitted for this
review and using the evidence-based, peer-reviewed guidelines referenced
above, this request is Peer Reviewer
Name/Credentials  Solis, Test, PhDInternal Medicine AttestationContact Information Peer to Peer contact attempt 1: 08/13/2014 02:46
PM, Central, Incoming Call, Successful, No Contact Made, Peer Contact Did
Not Change Determination'


i am trying to find the various font sizes and font face from this string.

i tried

print re.search("___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] xlrd package

2014-04-25 Thread Sunil Tech
Hi,

I want to know how many sheets can be created in Excel using xlrd package.

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


Re: [Tutor] Fwd: Puzzle - Next Step to our interviewing process - Pramati Technologies!

2014-04-23 Thread Sunil Tech
i have

{'extreme_fajita': [*{5: 4.0}*, *{6: 6.0}*],
 'fancy_european_water': [*{5: 8.0}*, *{6: 5.0}*]}

if the keys of the dictionaries(bold & italic) are equal. I want to add
bold dict values, & italic dict values.

result should some thing like this

[{5:12.0},{6:11.5}]

i tried to do...

but need your help.

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


Re: [Tutor] Fwd: Puzzle - Next Step to our interviewing process - Pramati Technologies!

2014-04-15 Thread Sunil Tech
Hi Danny,


Thank you for replying..

I need the python program which takes the attached csv & on running the
program which will give me the results as


 
Data File data.csv
1, 4.00, burger
1, 8.00, tofu_log
2, 5.00, burger
2, 6.50, tofu_log
 Program Input
program data.csv burger tofu_log
 Expected Output
=> 2, 11.5
---
 
Data File data.csv
3, 4.00, chef_salad
3, 8.00, steak_salad_sandwich
4, 5.00, steak_salad_sandwich
4, 2.50, wine_spritzer

Program Input
program data.csv chef_salad wine_spritzer
Expected Output
=> nil (or null or false or something to indicate that no matching
restaurant could be found)
---
 
Data File data.csv
5, 4.00, extreme_fajita
5, 8.00, fancy_european_water
6, 5.00, fancy_european_water
6, 6.00, extreme_fajita, jalapeno_poppers, extra_salsa
 Program Input
program data.csv fancy_european_water extreme_fajita
 Expected Output
=> 6, 11.0


On Tue, Apr 15, 2014 at 8:05 PM, Danny Yoo  wrote:

> So, what is your question?
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] reading a csv file

2014-04-15 Thread Sunil Tech
yes Alan, what you said is true.

Thank you.


On Tue, Apr 15, 2014 at 1:40 PM, Alan Gauld wrote:

> On 15/04/14 07:06, Sunil Tech wrote:
>
>> Hi,
>>
>> #!/usr/bin/python
>>
>> import csv
>> import sys
>>
>> def main():
>>  cr = csv.reader(open("data.csv","rb"))
>>  for row in cr:
>>  print row
>>
>
>  when i run this...
>>
>>
>>  cr = csv.reader(open("data.csv","rb"))
>> AttributeError: 'module' object has no attribute 'reader'
>>
>>
> The most common cause of this error is that you have
> created a file called csv.py which is masking the
> library module.
>
> Could that be the case here?
>
>
> --
> 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] Fwd: Puzzle - Next Step to our interviewing process - Pramati Technologies!

2014-04-14 Thread Sunil Tech
Kindly assess the problem carefully including all the possibilities,
including but not limited to:



1. Menu directly available(1 item or all items).

2. Menu available but distributed over multiple items.

3. Menu need not be present in all restaurants listed.

4. Menu not available at all.


Please complete the puzzle using the development language that you are
being interviewed for.

Most people have send responses that work for the dataset and the test
cases described along with the problem. However we do use a different
dataset and test cases that try and check some boundary conditions. We have
seen many solutions that work for the test cases below but fail with our
internally used test cases.



Because it is the Internet Age, but also it is a recession, the Comptroller
of the town of Jurgensville has decided to publish the prices of every item
on every menu of every restaurant in town, all in a single CSV file
(Jurgensville is not quite up to date with modern data
serializationmethods).  In addition, the restaurants of Jurgensville also
offer Value Meals, which are groups of several items, at a discounted
price.  The Comptroller has also included these Value Meals in the
file.  The file's format is:

 for lines that define a price for a single item:

restaurant ID, price, item label

 for lines that define the price for a Value Meal (there can be any number
of

items in a value meal)

restaurant ID, price, item 1 label, item 2 label, ...

 All restaurant IDs are integers, all item labels are lower case letters and

underscores, and the price is a decimal number.

 Because you are an expert software engineer, you decide to write a program
that accepts the town's price file, and a list of item labels that someone
wants to eat for dinner, and outputs the restaurant they should go to, and
the total price it will cost them.  It is okay to purchase extra items, as
long as the total cost is minimized.



Here are some sample data sets, program inputs, and the expected result:

 

Data File data.csv

1, 4.00, burger

1, 8.00, tofu_log

2, 5.00, burger

2, 6.50, tofu_log

 Program Input

program data.csv burger tofu_log

 Expected Output

=> 2, 11.5

---

 

Data File data.csv

3, 4.00, chef_salad

3, 8.00, steak_salad_sandwich

4, 5.00, steak_salad_sandwich

4, 2.50, wine_spritzer



Program Input

program data.csv chef_salad wine_spritzer

Expected Output

=> nil (or null or false or something to indicate that no matching

restaurant could be found)

---

 

Data File data.csv

5, 4.00, extreme_fajita

5, 8.00, fancy_european_water

6, 5.00, fancy_european_water

6, 6.00, extreme_fajita, jalapeno_poppers, extra_salsa

 Program Input

program data.csv fancy_european_water extreme_fajita

 Expected Output

=> 6, 11.0

---

 We have included all these samples in a single data file,
sample_data.csv.Please include instructions for how to run your program
with your submission.


sample_data.csv
Description: MS-Excel spreadsheet
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] reading a csv file

2014-04-14 Thread Sunil Tech
Please ignore previous email.

this error occurred as i had previously created .pyc file...
after deleting that .pyc file.. now it is working fine.


Thank you.



On Tue, Apr 15, 2014 at 11:36 AM, Sunil Tech wrote:

> Hi,
>
> #!/usr/bin/python
>
> import csv
> import sys
>
> def main():
> cr = csv.reader(open("data.csv","rb"))
> for row in cr:
> print row
>
> if __name__ == "__main__":
> sys.exit(main())
>
>
>
> when i run this...
>
> i get
>
> Traceback (most recent call last):
>   File "data.py", line 14, in 
> sys.exit(main())
>   File "data.py", line 9, in main
> cr = csv.reader(open("data.csv","rb"))
> AttributeError: 'module' object has no attribute 'reader'
>
>
> can anyone correct me please.
>
> thank you in advance.
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] reading a csv file

2014-04-14 Thread Sunil Tech
Hi,

#!/usr/bin/python

import csv
import sys

def main():
cr = csv.reader(open("data.csv","rb"))
for row in cr:
print row

if __name__ == "__main__":
sys.exit(main())



when i run this...

i get

Traceback (most recent call last):
  File "data.py", line 14, in 
sys.exit(main())
  File "data.py", line 9, in main
cr = csv.reader(open("data.csv","rb"))
AttributeError: 'module' object has no attribute 'reader'


can anyone correct me please.

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


[Tutor] Dict

2013-11-26 Thread Sunil Tech
Hi Friends,

Is it possible to sort dict & to get result as dict?
if it is possible, please give some example.

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


Re: [Tutor] Date time

2013-11-25 Thread Sunil Tech
Thank you Danny


On Mon, Nov 25, 2013 at 2:36 PM, Danny Yoo  wrote:

> On Mon, Nov 25, 2013 at 12:31 AM, Sunil Tech 
>  wrote:
>
> I want to know, what difference is in between *mxDateTime & datetime of
>> python?*
>> looking for your comments...
>>
>
>
> According to the mxDateTime web site, it provides a compatible interface
> to the standard library's version.
>
> http://www.egenix.com/products/python/mxBase/mxDateTime/
>
>
> I'm trying to remember the history of things, but unfortunately my memory
> can't be trusted.  But I believe mxDateTime was developed first, and
> influenced the design of the standard library's version.
>
>
> I'm trying to see if I can find supporting evidence for this guess... ok,
> the one in the standard library came in July 2003, according to:
>
>
> http://docs.python.org/release/2.3/whatsnew/node18.html#SECTION000181
>
> We can do a few more searches to see that references to mxDateTime did
> exist before then.
>
> For example, here's a reference from back in April 1999:
>
> http://code.activestate.com/lists/python-list/208/
>
>
> We can also see that the developer, M.-A. Lemburg,  worked to get things
> compatible between the two implementations:
>
> https://mail.python.org/pipermail/python-dev/2003-January/032100.html
>
>
> So that should help explain why there are two libraries out there with the
> same interface.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Date time

2013-11-25 Thread Sunil Tech
I want to know, what difference is in between *mxDateTime & datetime of
python?*
looking for your comments...

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


Re: [Tutor] 3 Dimensional Dictionaries

2013-07-22 Thread Sunil Tech
On Tuesday, July 23, 2013, Sunil Tech  wrote:
> THANK YOU ALL for your time.
>
> The first format which I pasted was from the DB
>
> The second format(exactly the same), is to be sent to the view.
>
> If the logic can be fitted in One or two methods it'll help me to easily
understand & to apply.
>
> so I request you to help...
>
>
> On Sunday, July 21, 2013, Alan Gauld  wrote:
>> On 20/07/13 11:17, Sunil Tech wrote:
>>>
>>> Hi Everyone,
>>>
>>> I have a list of dictionaries like
>>>
>>> world =
>>>
[{'continent':'Asia','continent_code':1,'ocean':'Pacific','country':'India','country_code':1,'state':'Kerala',
>>> 'state_pin':51},
>>
>>>
>>> i am trying to to make it in this format
>>>
>>> world = [{'continent':'Asia', 'ocean':'Pacific',
>>> 'countries':[{'country':'India',
>>> 'states':[{'state':'Kerala', 'state_pin':51},
>>> {'state':'Karnataka', 'state_pin':52}]
>>> }]
>>> },
>>
>>> Please help me in this regard.
>>
>> In what regard? Where do you need the help?
>> You seem to know the data format you want?
>>
>> The only thing I'd suggest is to consider using classes if you are
familiar with them.
>>
>> world => list of continents
>> continent => class containing countries
>> country => class containing states
>> state => class containing data
>>
>> It then becomes easier to build helper methods to extract/manipulate the
data you are interested in.
>>
>> Alternatively, if you have a large amount of data a database may be
another option. Swap table for class above and use SQL to manage the data.
>>
>> But other than those suggestions I don't know what kind of
>> help you want?
>>
>> --
>> Alan G
>> Author of the Learn to Program web site
>> http://www.alan-g.me.uk/
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 3 Dimensional Dictionaries

2013-07-22 Thread Sunil Tech
THANK YOU ALL for your time.

The first format which I pasted was from the DB

The second format(exactly the same), is to be sent to the view.

If the logic can be fitted in One or two methods it'll help me to easily
understand & to apply.

so I request you to help...


On Sunday, July 21, 2013, Alan Gauld  wrote:
> On 20/07/13 11:17, Sunil Tech wrote:
>>
>> Hi Everyone,
>>
>> I have a list of dictionaries like
>>
>> world =
>>
[{'continent':'Asia','continent_code':1,'ocean':'Pacific','country':'India','country_code':1,'state':'Kerala',
>> 'state_pin':51},
>
>>
>> i am trying to to make it in this format
>>
>> world = [{'continent':'Asia', 'ocean':'Pacific',
>> 'countries':[{'country':'India',
>> 'states':[{'state':'Kerala', 'state_pin':51},
>> {'state':'Karnataka', 'state_pin':52}]
>> }]
>> },
>
>> Please help me in this regard.
>
> In what regard? Where do you need the help?
> You seem to know the data format you want?
>
> The only thing I'd suggest is to consider using classes if you are
familiar with them.
>
> world => list of continents
> continent => class containing countries
> country => class containing states
> state => class containing data
>
> It then becomes easier to build helper methods to extract/manipulate the
data you are interested in.
>
> Alternatively, if you have a large amount of data a database may be
another option. Swap table for class above and use SQL to manage the data.
>
> But other than those suggestions I don't know what kind of
> help you want?
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 3 Dimensional Dictionaries

2013-07-20 Thread Sunil Tech
Hi,

yes Dominik & the result should be in that format as stated.


On Sat, Jul 20, 2013 at 3:58 PM, Dominik George  wrote:

> Hi,
>
> > world =
> >
> [{'continent':'Asia','continent_code':1,'ocean':'Pacific','country':'India','country_code':1,'state':'Kerala',
> > 'state_pin':51},
> >  [...]
> >
> > i am trying to to make it in this format
> >
>
> to clarify the task at hand: this is comparible to SQL's GROUP BY
> clause, right?
>
> -nik
>
> --
>  Auf welchem Server liegt das denn jetzt…?
>  Wenn es nicht übers Netz kommt bei Hetzner, wenn es nicht
> gelesen wird bei STRATO, wenn es klappt bei manitu.
>
> PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17  FD26 B79A 3C16 A0C4 F296
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] 3 Dimensional Dictionaries

2013-07-20 Thread Sunil Tech
Hi Everyone,

I have a list of dictionaries like

world =
[{'continent':'Asia','continent_code':1,'ocean':'Pacific','country':'India','country_code':1,'state':'Kerala',
'state_pin':51},
 
{'continent':'Asia','continent_code':1,'ocean':'Pacific','country':'India','country_code':1,'state':'Karnataka',
'state_pin':52},
 
{'continent':'Africa','continent_code':2,'ocean':'Atlantic','country':'Egypt','country_code':2,'state':'East
Egypt', 'state_pin':71},
 
{'continent':'Africa','continent_code':2,'ocean':'Atlantic','country':'Egypt','country_code':2,'state':'West
Egypt', 'state_pin':72},
 
{'continent':'Africa','continent_code':2,'ocean':'Atlantic','country':'Egypt','country_code':2,'state':'North
Egypt', 'state_pin':73}]


i am trying to to make it in this format

world = [{'continent':'Asia', 'ocean':'Pacific',
 'countries':[{'country':'India',
'states':[{'state':'Kerala', 'state_pin':51},
 {'state':'Karnataka', 'state_pin':52}]
}]
 },
{'continent':'Africa', 'ocean':'Atlantic',
 'countries':[{'country':'Egypt',
'states':[{'state':'East Egypt', 'state_pin':71},
 {'state':'West Egypt', 'state_pin':72},
{'state':'North Egypt', 'state_pin':73}]
 }]
}
]


Please help me in this regard.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Query String

2013-02-19 Thread Sunil Tech
Thank you Alan.





On Tue, Feb 19, 2013 at 2:44 PM, Alan Gauld wrote:

> On 19/02/13 07:30, Sunil Tech wrote:
>
>>
>> Here i request, can you tell me what is Query String with some examples?
>>
>
> It depends on the context but I suspect you mean in the context of a web
> app? In that case a query string is the bit at the end of a URL that
> includes the search parameters etc. Thus if I do a search on Google for
> "query string" the url used is:
>
> https://www.google.co.uk/#hl=**en&sugexp=les%3B&gs_rn=3&gs_**ri=psy-<https://www.google.co.uk/#hl=en&sugexp=les%3B&gs_rn=3&gs_ri=psy->
> ab&tok=XeR8I7yoZ93k_zpsfFWQeg&**cp=8&gs_id=i7&xhr=t&q=query+**string&
> es_nrs=true&pf=p&tbo=d&biw=**1375&bih=897&sclient=psy-ab&**oq=query+st&
> gs_l=&pbx=1&bav=on.2,or.r_gc.**r_pw.r_cp.r_qf.&bvm=bv.**42553238,d.d2k&
> fp=e58955d3a8f3f3a1
>
> And everything after the uk/ is the query string.
>
> That particular search brings back lots of links about query strings.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Query String

2013-02-18 Thread Sunil Tech
Hi All,

I thank you all, for all the responses.
& teaching us to learn Python.

Here i request, can you tell me what is Query String with some examples?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] If a method has no return type?

2013-02-07 Thread Sunil Tech
Thank you Wesley, Kal & tutor


On Thu, Feb 7, 2013 at 12:07 PM, Kal Sze  wrote:

> Dear Sunil,
>
> No method or function in Python has a *static* return type. That's
> because Python is by nature a dynamic language, with duck typing and
> dynamic dispatch. In fact, any method or function may well return any
> of a number of different types:
>
> def crazy_function(return_int)
> if return_int:
> return 1
> else:
> return 'foo'
>
> It's probably bad design, but there is nothing in the Python grammar
> and semantics that stops you from doing that.
>
> So your question is better phrased as: if I don't explicitly return
> anything, what is returned?
>
> The answer to that would be: the None object
>
> Cheers,
> Kal
>
> On 7 February 2013 14:09, Sunil Tech  wrote:
> > If a method has no return type?
> > what will it return?
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] If a method has no return type?

2013-02-06 Thread Sunil Tech
If a method has no return type?
what will it return?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Files Merging

2012-10-11 Thread Sunil Tech
Thanks all for your immediate responses :)

On Thu, Oct 11, 2012 at 6:20 PM, Joel Goldstick wrote:

> On Thu, Oct 11, 2012 at 8:30 AM, eryksun  wrote:
> > On Thu, Oct 11, 2012 at 7:13 AM, Sunil Tech 
> wrote:
> >>
> >> text1 contains
> >> This is from Text1 --- 1st line
> >> 
> >>
> >> text2 contains
> >> This is from Text2 --- 1st line
> >> 
> >>
> >> i want result in text3 like
> >> This is from Text1 --- 1st line
> >> This is from Text2 --- 1st line
> >> 
>
> zip gets you tuples.  map can operate on those tuples
>
> I just tried this:
> >>> x = [1,2,3]
> >>> y = [4,5,6]
> >>> def print_2(t):
> ...   print t[0], t[1]
> ...
> >>> z = zip(x,y)
> >>> z
> [(1, 4), (2, 5), (3, 6)]
>
> >>> r = map(print_2, z)
> 1 4
> 2 5
> 3 6
> >>>
>
> You need to write a function that writes the tuple to a file.  It will
> look something like my print_2() function
> --
> Joel Goldstick
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Files Merging

2012-10-11 Thread Sunil Tech
i used zip(), but it gives me result in list of tuples format.
But i don't get in a exact expect format (as mentioned)
no loopings are allowed.

On Thu, Oct 11, 2012 at 5:30 PM, Dave Angel  wrote:

> On 10/11/2012 07:13 AM, Sunil Tech wrote:
> > Hi all,
> >
> > Greetings to you...
> > it been so helpful for me to go through your all mails & support & i wish
> > it still continues.
> >
> > I have two text files.
> >
> > text1 contains
> >
> > This is from Text1 --- 1st line
> > This is from Text1 --- 2nd line
> > This is from Text1 --- 3rd line
> > This is from Text1 --- 4th line
> > This is from Text1 --- 5th line
> >
> > text2 contains
> > This is from Text2 --- 1st line
> > This is from Text2 --- 2nd line
> > This is from Text2 --- 3rd line
> > This is from Text2 --- 4th line
> > This is from Text2 --- 5th line
> >
> >
> > i want result in text3 like
> >
> > This is from Text1 --- 1st line
> > This is from Text2 --- 1st line
> > This is from Text1 --- 2nd line
> > This is from Text2 --- 2nd line
> > This is from Text1 --- 3rd line
> > This is from Text2 --- 3rd line
> > This is from Text1 --- 4th line
> > This is from Text2 --- 4th line
> > This is from Text1 --- 5th line
> > This is from Text2 --- 5th line
> >
> > but condition is "should not use any loops"
> >
> > waiting for your reply,
> > thank you in advance.
> >
> > Regards,
> > Sunil G.
> >
> >
>
> What are the other constraints on this homework assignment?  Are list
> comprehensions permitted?  Seems likely you can do it readily with a
> list comprehension using zip().  One line, total.
>
>
>
> --
>
> DaveA
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Files Merging

2012-10-11 Thread Sunil Tech
Hi all,

Greetings to you...
it been so helpful for me to go through your all mails & support & i wish
it still continues.

I have two text files.

text1 contains

This is from Text1 --- 1st line
This is from Text1 --- 2nd line
This is from Text1 --- 3rd line
This is from Text1 --- 4th line
This is from Text1 --- 5th line

text2 contains
This is from Text2 --- 1st line
This is from Text2 --- 2nd line
This is from Text2 --- 3rd line
This is from Text2 --- 4th line
This is from Text2 --- 5th line


i want result in text3 like

This is from Text1 --- 1st line
This is from Text2 --- 1st line
This is from Text1 --- 2nd line
This is from Text2 --- 2nd line
This is from Text1 --- 3rd line
This is from Text2 --- 3rd line
This is from Text1 --- 4th line
This is from Text2 --- 4th line
This is from Text1 --- 5th line
This is from Text2 --- 5th line

but condition is "should not use any loops"

waiting for your reply,
thank you in advance.

Regards,
Sunil G.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] What made Python differ from other Languages?

2012-02-20 Thread Sunil Tech
*I am Beginner (very little i know), i want to know what are new things i
can find in Python.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need Explanation...

2011-12-11 Thread Sunil Tech
*Thank you all...*
*for your previous time. :)
*
On Sun, Dec 11, 2011 at 2:56 PM, Alan Gauld wrote:

> On 11/12/11 03:23, Lie Ryan wrote:
>
>  If returning 'self' is the default expected behavior, it would cause
>> inconsistencies with respect to immutable types. For example, `5
>> .__add__(2)`, one could expect it to return 5 instead of 7.
>>
>
> That's not a case where default behaviour would be invoked.
> I'm talking about where None is currently returned. Returning None in the
> above case would make arithmetic impossible.
>
> In "modifying" immutables you have to return the modified value, that
> wouldn't change. And the same applies in Smalltalk, you only return self as
> a default value in those situations where there is no specific return value
> required (as Steve put it, for a "procedure like" function).
>
> It just makes those procedure like functions more usable IMHO.
>
>
>  While I liked the attraction of "fluent interface" of being able to
>> easily chain function calls, it is inherently more inconsistent than
>> what Python are doing.
>>
>
> I disagree.
>
> However there are so many Smalltalk like features in Python that I'm sure
> Guido was well aware of returning self as an option and he obviously
> deliberately chose not to. So he presumably felt the gains were outweighed
> by the negatives.
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Need Explanation...

2011-12-09 Thread sunil tech
*hi,*
*
*
*Consider a list: a = [1,2,3]*
*
*
*& a simple function, which when called it will append 100 to the list.*
*
*
*def app(x):*
* return x.append(100)*
*
*
*p = app(a)*
*
*
*now list holds appended value [1,2,3,100]*
*but p is empty... why it is?*
*
*
*please teach.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Dictionary to variable copy

2011-12-08 Thread sunil tech
*Can i copy the content if a dictionary in to another variable, with out
any link between the dictionary & the variable?

if so, please teach.
*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Converting files

2011-04-12 Thread sunil tech
thank you for all your valuable suggestions...
but i want it to be converted using python code ..

On Tue, Apr 12, 2011 at 2:38 AM, Evans Anyokwu  wrote:

> I use Openoffice and it has an option to export your files to .pdf and lots
> of other file formats.
> It's a free download - and has all the usual Office applications...
>
> Search for 'OpenOffice' online.
>
>
> On Mon, Apr 11, 2011 at 9:48 PM, Alan Gauld wrote:
>
>>
>> "sunil tech"  wrote
>>
>>
>>  is there any way to convert any file (eg: document files & image files)
>>> to
>>> .pdf?
>>>
>>> if so, kindly share...
>>>
>>
>> Install a PDF print driver and then print the file to that printer.
>> Set it to save as a file. Then if its printable you can get it as a PDF.
>>
>> You can do the same with postscript(and postscript drivers
>> come with most OS). Then send the postscript file to Adobe's
>> web site to get them to generate the PDF from postscript.
>> (You can also download free convertors)
>>
>> Finally, and because this is a Python list,  you could use a
>> Python library and generate the file yourself - but while thats
>> ok for your own data its a lot harder for many file types!
>>
>> HTH,
>>
>> --
>> Alan Gauld
>> Author of the Learn to Program web site
>> http://www.alan-g.me.uk/
>>
>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Converting files

2011-04-11 Thread sunil tech
Hi all...

is there any way to convert any file (eg: document files & image files) to
.pdf?

if so, kindly share...

thank you in advance.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] list of dictionary

2011-02-24 Thread sunil tech
Hi all...

i have d=[{'qty':0.0},{'qty':0.0}]

when all the qty is 0.0,
i want to perform some print operation
(only at once, after it checks everything in the list of dictionary 'd')...

if its not 0.0,
print some message...

Thank you in advance
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor