[Tutor] Deleting specified files using a python program...help with code?

2008-06-29 Thread Saad Javed
I transfer files a lot between my windows and linux partitions...these
folders sometimes contain *.db and *.ini files which are not recognized or
used by linux. So i tried to write a program to crawl through my home dir
and remove these files...I'm *very* new to programming and python so please
be gentle. Here is the code:

*import os

list = ['*.ini', '*.db']

for root, dirs, files in os.walk('/home/saad'):
**for list in files:
**os.remove(os.path.join('root', 'list'))
print 'done'*

Unfortunately its a bit too efficient and nearly wiped my home dir before i
manually killed it. Again...treat me like a super noob.

Saad
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Deleting specified files using a python program...help with code?

2008-06-29 Thread Saad Javed
Thanks a lot for all the help! If there were a module named
"common-sense" i could insert into my brain...I wouldn't have lost my
/home. Thanks again

Saad
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Deleting specified files using a python program...help with code?

2008-06-30 Thread Saad Javed
Here's the working code for my problem. But i tried it to post 'No
files found' in case no specified files are found. It doesn't do that.
Just simply exits.

dir_input = raw_input('Enter dir: ')

win_trace = ['*.ini', '*.db']

for root, dirs, files in os.walk(dir_input):
for trace in win_trace:
win_trace_path = os.path.join(root, trace)
for filename in glob.glob(win_trace_path):
if os.path.exists(filename):
print filename
else:   
print 'No files found'
confirmation = raw_input('Confirm removal: ')
if confirmation == 'y':
os.remove(filename)
print 'done'
elif confirmation == 'n':
pass
    else:
    sys.exit()

On Sun, Jun 29, 2008 at 9:13 PM, Saad Javed <[EMAIL PROTECTED]> wrote:
> I transfer files a lot between my windows and linux partitions...these
> folders sometimes contain *.db and *.ini files which are not recognized or
> used by linux. So i tried to write a program to crawl through my home dir
> and remove these files...I'm *very* new to programming and python so please
> be gentle. Here is the code:
>
> import os
>
> list = ['*.ini', '*.db']
>
> for root, dirs, files in os.walk('/home/saad'):
> for list in files:
> os.remove(os.path.join('root', 'list'))
> print 'done'
>
> Unfortunately its a bit too efficient and nearly wiped my home dir before i
> manually killed it. Again...treat me like a super noob.
>
> Saad
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Deleting specified files using a python program...help with code?

2008-07-01 Thread Saad Javed
Thankyou cedric!

On 6/29/08, Saad Javed <[EMAIL PROTECTED]> wrote:
> I transfer files a lot between my windows and linux partitions...these
> folders sometimes contain *.db and *.ini files which are not recognized or
> used by linux. So i tried to write a program to crawl through my home dir
> and remove these files...I'm *very* new to programming and python so please
> be gentle. Here is the code:
>
> *import os
>
> list = ['*.ini', '*.db']
>
> for root, dirs, files in os.walk('/home/saad'):
> **for list in files:
> **os.remove(os.path.join('root', 'list'))
> print 'done'*
>
> Unfortunately its a bit too efficient and nearly wiped my home dir before i
> manually killed it. Again...treat me like a super noob.
>
> Saad
>

-- 
Sent from Gmail for mobile | mobile.google.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help with a simple problem

2009-01-03 Thread Saad Javed
Hi Tutors,

I'm trying to create a simple GUI using pyqt4 in which pressing a button
causes execution of a system command. Here's the code, please help me out. I
can't figure out whats wrong. Thanks

import sys
import os
from PyQt4 import QtGui, QtCore

class TestGui(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setGeometry(300, 300, 140, 50)
self.setWindowTitle('testing')


self.setWindowIcon(QtGui.QIcon('/usr/share/pixmaps/blueradio-48.png'))

*dial = QtGui.QPushButton('Dial', self)
dial.setGeometry(10, 10, 60, 35)
self.connect(dial, QtCore.SIGNAL('clicked()'),
QtGui.qApp, QtCore.SLOT(os.system('wvdial ptcl')))*

quit = QtGui.QPushButton('Quit', self)
quit.setGeometry(70, 10, 60, 35)
self.connect(quit, QtCore.SIGNAL('clicked()'), QtGui.qApp,
QtCore.SLOT('quit()'))

app = QtGui.QApplication(sys.argv)
testgui = TestGui()
testgui.show()
sys.exit(app.exec_())
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with a simple problem

2009-01-03 Thread Saad Javed
The bold was intentional. I was trying to get a shell command (wvdial) to
run when a button is pressed. The error I get is:

Traceback (most recent call last):
  File "testgui.py", line 26, in 
testgui = TestGui()
  File "testgui.py", line 19, in __init__
self.connect(dial, QtCore.SIGNAL('clicked()'), QtGui.qApp,
QtCore.SLOT(os.system('wvdial')))
TypeError: argument 1 of SLOT() has an invalid type

Was that helpful?

On Sat, Jan 3, 2009 at 9:18 PM, bob gailer  wrote:

>  Saad Javed wrote:
>
> Hi Tutors,
>
>
> Hi and welcome to the tutor list. We can help you better if you tell us
> what the problem is. What did you expect? What did you get?
>
> Most of us don't have the time or energy to read code when we don't know
> what we are looking for.
>
> Some of your code is bold. Why? What does that mean?
>
> Please think about this and repost with more information.
>
> If you get an "error" (exception) please post the traceback
>
>
> I'm trying to create a simple GUI using pyqt4 in which pressing a button
> causes execution of a system command. Here's the code, please help me out. I
> can't figure out whats wrong. Thanks
>
> import sys
> import os
> from PyQt4 import QtGui, QtCore
>
> class TestGui(QtGui.QWidget):
> def __init__(self, parent=None):
> QtGui.QWidget.__init__(self, parent)
> self.setGeometry(300, 300, 140, 50)
> self.setWindowTitle('testing')
>
>
> self.setWindowIcon(QtGui.QIcon('/usr/share/pixmaps/blueradio-48.png'))
>
> *dial = QtGui.QPushButton('Dial', self)
> dial.setGeometry(10, 10, 60, 35)
> self.connect(dial, QtCore.SIGNAL('clicked()'),
> QtGui.qApp, QtCore.SLOT(os.system('wvdial ptcl')))*
>
> quit = QtGui.QPushButton('Quit', self)
> quit.setGeometry(70, 10, 60, 35)
> self.connect(quit, QtCore.SIGNAL('clicked()'), QtGui.qApp,
> QtCore.SLOT('quit()'))
>
> app = QtGui.QApplication(sys.argv)
> testgui = TestGui()
> testgui.show()
> sys.exit(app.exec_())
>
> --
>
> ___
> Tutor maillist  -  
> tu...@python.orghttp://mail.python.org/mailman/listinfo/tutor
>
>
>
> --
> Bob Gailer
> Chapel Hill NC
> 919-636-4239
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with a simple problem

2009-01-03 Thread Saad Javed
I implemented a dial function and passed it to the QtCore.SLOT(), which
worked fine. Thanks everyone!

On Sat, Jan 3, 2009 at 10:33 PM, Kent Johnson  wrote:

> On Sat, Jan 3, 2009 at 11:39 AM, Saad Javed  wrote:
> > The bold was intentional. I was trying to get a shell command (wvdial) to
> > run when a button is pressed. The error I get is:
> >
> > Traceback (most recent call last):
> >   File "testgui.py", line 26, in 
> > testgui = TestGui()
> >   File "testgui.py", line 19, in __init__
> > self.connect(dial, QtCore.SIGNAL('clicked()'), QtGui.qApp,
> > QtCore.SLOT(os.system('wvdial')))
> > TypeError: argument 1 of SLOT() has an invalid type
> >
> > Was that helpful?
>
> Maybe :-)
>
> From a quick look at the docs, it seems that QtCore.SLOT() is used to
> get a reference to a Qt function. When you want to use your own
> function as the target of an action, you just pass the function
> directly. Try this:
> self.connect(dial, QtCore.SIGNAL('clicked()'),
> QtGui.qApp, lambda: os.system('wvdial'))
>
> or define a named function that calls os.system() and pass the
> function to connect().
>
> Kent
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] help writing functions

2012-02-22 Thread Saad Javed
I am learning python and need guidance for writing some code. I've written
a simple program (with pointers from people) that parses an tv show xml
feed and prints their values in plain text after performing some string
operations.

[CODE]feed = urllib.urlopen(rssPage) #rssPage: address of xml feed
tree = etree.parse(feed)
x = tree.xpath("/rss/channel/item/title/text()")
x = str(x[0])
for tag in tags: #tags is a list of items like hdtv, xvid, 720p etc
x = re.sub(r'\b' + tag + r'\b', '', x)
z = re.sub(r'[^\w\s]', '', x)
y = tree1.xpath("/rss/channel/item/pubDate/text()")
print "%s - %s" %(z.rstrip(), y[0][:16])[/CODE]

The code works fine (prints the name of the show and date). Now since I am
parsing more than one feed, I thought the better way was to split the
functionality into diff functions: one to get the values and the other to
remove the tags. I'm still *very* new to python and came up with the
following code.

[CODE]def get_value(feed):
try:
url = urllib2.urlopen(feed)
 tree = etree.parse(url)
x = tree.xpath("/rss/channel/item/title/text()")
 y = tree.xpath("/rss/channel/item/pubDate/text()")
x = str(x[0])
 y = str(y[0][:16])
return x
return y
 except SyntaxError:
print 'Service Unavailable'
pass

def del_tag(x):
tags = ['HDTV', 'LOL', 'VTV', 'x264', 'DIMENSION', 'XviD', '720P',
'IMMERSE', '720p', 'X264']
 for tag in tags:
x = re.sub(r'\b' + tag + r'\b', '', x)
 y = re.sub(r'[^\w\s]', '', x)
def main():
a = get_value(rssPage)
 b = del_tag(a)
print b
 if __name__ == '__main__':
main()[/CODE]

My desired working is to supply the xml feed address to the
[B]get_value[/B] function which returns the title and date as strings
assigned to [B]x[/B] and [B]y[/B]. Then I run the [B]del_tag[/B] function
on the title string ([B]x[/B]) and remove tags and the [B]main()[/B]
function prints both [B]x[/B] and [B]y[/B] (Title, Date).

Running this code returns [B]None[/B].

Let the teaching begin :)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help writing functions

2012-02-23 Thread Saad Javed
Sorry for the formatting. Added return statements to both functions. Adding
return [x, y] to get_value func. That solved the problem. Thank you! :)

Saad

On Thursday, February 23, 2012, Alan Gauld wrote:

> On 23/02/12 00:59, Saad Javed wrote:
>
>  [CODE]feed = urllib.urlopen(rssPage) #rssPage: address of xml feed
>> tree = etree.parse(feed)
>> x = tree.xpath("/rss/channel/item/**title/text()")
>> x = str(x[0])
>> for tag in tags: #tags is a list of items like hdtv, xvid, 720p etc
>> x = re.sub(r'\b' + tag + r'\b', '', x)
>> z = re.sub(r'[^\w\s]', '', x)
>> y = tree1.xpath("/rss/channel/**item/pubDate/text()")
>> print "%s - %s" %(z.rstrip(), y[0][:16])[/CODE]
>>
>
> Please don;t insert wiki style markers, its just confusing.
> Also please use plain text for email otherwise the formatting
> tends to get lost.
>
>  [CODE]def get_value(feed):
>> try:
>> url = urllib2.urlopen(feed)
>> tree = etree.parse(url)
>> x = tree.xpath("/rss/channel/item/**title/text()")
>> y = tree.xpath("/rss/channel/item/**pubDate/text()")
>> x = str(x[0])
>> y = str(y[0][:16])
>> return x
>> return y
>>
>
> This will always return x and never y because a return statement
> terminates the function. If you want to return both values you need to put
> them in the same return statement:
>
> return x,y
>
> If you want to return only one you need to select which
> with an if/else.
>
> return x if  else y
>
> or just
>
> if 
>   return x
> else
>   return y
>
> If you prefer.
>
>  except SyntaxError:
>>
>
> You should probably not try catching Syntax errors since thats usually a
> fault in your code! Instead fix the syntax error.
>
>  def del_tag(x):
>> tags = ['HDTV', 'LOL', 'VTV', 'x264', 'DIMENSION', 'XviD', '720P',
>> 'IMMERSE', '720p', 'X264']
>> for tag in tags:
>> x = re.sub(r'\b' + tag + r'\b', '', x)
>> y = re.sub(r'[^\w\s]', '', x)
>>
>
> You don't return x or y so they get thrown away at the end of the
> function. Which makes the whole thing a waste of space...
>
>  def main():
>> a = get_value(rssPage)
>> b = del_tag(a)
>> print b
>> if __name__ == '__main__':
>> main()[/CODE]
>>
>> Running this code returns [B]None[/B].
>>
>
> None is the default return value if you do not provide one.
> main has no return statement. Neither does del_tag()
> Both main and del_tag will therefore return None.
>
> HTH
> --
> 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] Print items from 3 lists in order

2012-10-21 Thread Saad Javed
Hi,
a = ['Ron', 'Harry', 'Hermoine']
b = ['25th oct', '27th oct', '29th oct']
c = ['Charms', 'DADA', 'Potions']
I want to print like this:
Ron - 25th oct
Charms
Harry - 27th oct
DADA
Hermoine - 29th oct
Potions

The items in each list are populated dynamically so I don't know how many
items will be there in each list, every time the program runs.
I tried:
>>> for x in zip(a, b, c): print x
But that gives:
('Ron', '25th oct', 'Charms')
('Harry', '27th oct', 'DADA')
('Hermoine', '29th oct', 'Potions')

???

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


[Tutor] Populating a list

2012-10-21 Thread Saad Javed
My program downloads multiple entry values from the net. I'm trying to
combine them in a list in a particular sequence.

l = []
feed1 = urllib2.urlopen(rssPage1)
tree1 = etree.parse(feed1)
x = tree1.xpath("/rss/channel/item/title/text()")
y = tree1.xpath("/rss/channel/item/pubDate/text()")
z = tree1.xpath("/rss/channel/item/link/text()")
for e, f, g in zip(x, y, z):
l.append([e, f, g])
print l

The problem I'm facing is that the values don't combine into a single list
("l"). It keeps printing multiple lists with three values e, f, g as the
xml tree is parsed.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Populating a list

2012-10-22 Thread Saad Javed
l.extend does work. Thanks!

On Monday, October 22, 2012, Saad Javed wrote:

> My program downloads multiple entry values from the net. I'm trying to
> combine them in a list in a particular sequence.
>
> l = []
> feed1 = urllib2.urlopen(rssPage1)
> tree1 = etree.parse(feed1)
> x = tree1.xpath("/rss/channel/item/title/text()")
> y = tree1.xpath("/rss/channel/item/pubDate/text()")
> z = tree1.xpath("/rss/channel/item/link/text()")
> for e, f, g in zip(x, y, z):
>  l.append([e, f, g])
> print l
>
> The problem I'm facing is that the values don't combine into a single list
> ("l"). It keeps printing multiple lists with three values e, f, g as the
> xml tree is parsed.
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Creating a list from other lists

2012-10-22 Thread Saad Javed
Hi,

I'm trying to create a list (L) from items of different lists (a, b, c) but
in a specific order (L = [[a1, b1, c1], [a2, b2, c2]...etc])
L = []
a = [1, 2, 3, 4]
b = ['a', 'b', 'c', 'd']
c = [2009, 2010, 2011, 2012]

for x, y , z in zip(a, b, c):
L.extend([x, y, z])
print L

But this outputs:
[[1, 'a', 2009]]
[[1, 'a', 2009], [2, 'b', 2010]]
[[1, 'a', 2009], [2, 'b', 2010], [3, 'c', 2011]]
[[1, 'a', 2009], [2, 'b', 2010], [3, 'c', 2011], [4, 'd', 2012]]

I just want L = [[1, 'a', 2009], [2, 'b', 2010], [3, 'c', 2011], [4, 'd',
2012]]

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


[Tutor] For - if - else loop; print selective output

2012-10-24 Thread Saad Javed
Hi,

a = [['jimmy', '25', 'pancakes'], ['tom', '23', 'brownies'], ['harry',
'21', 'cookies']]
for i in a:
if (i[1] == '25' or i[1] == '26'):
print 'yes'
else:
print 'Not found'

This prints:
yes
not found

I want it to print "yes" for each positive match but nothing for a negative
match. However if all matches are negative, I want it to print "Not found"
once (That bit the code already does). I do I get it to print "yes" only in
a mix result situation?

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


Re: [Tutor] For - if - else loop; print selective output

2012-10-24 Thread Saad Javed
Let me modify this example:

a = [['jimmy', '25', 'pancakes'], ['tom', '23', 'brownies'], ['harry',
'21', 'cookies']]
for i in a:
*b = i[0]*
if (i[1] == '25' or i[1] == '26'):
print *b*
else:
print 'Not found'

This will output:
*jimmy*
*Not found*
*Not found*
*
*
How do I print positive matches (*jimmy*) only and not (*Not found*). I
also want *Not found *to print only *once *if there are no positive matches.

On Wednesday, October 24, 2012, Saad Javed wrote:

> Hi,
>
> a = [['jimmy', '25', 'pancakes'], ['tom', '23', 'brownies'], ['harry',
> '21', 'cookies']]
> for i in a:
> if (i[1] == '25' or i[1] == '26'):
> print 'yes'
> else:
> print 'Not found'
>
> This prints:
> yes
> not found
>
> I want it to print "yes" for each positive match but nothing for a
> negative match. However if all matches are negative, I want it to print
> "Not found" once (That bit the code already does). I do I get it to print
> "yes" only in a mix result situation?
>
> Saad
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] For - if - else loop; print selective output

2012-10-24 Thread Saad Javed
Thanks!

If not matched: < does it mean that "if the value of matched is not
true, print Not found"?
print "Not found"
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] run with default value if input not given

2012-10-28 Thread Saad Javed
Hi,

#!/usr/bin/env python

import sys

x = 'Saad is a boy'

def main(x):
a = []
b = x.split(' ')
for item in b:
a.append(item)
print a
if __name__ == '__main__':
x = sys.argv[1]
main(x)


How can I make this program run with the default value of x if I don't
specify an argument at the command line?
It should do this:

saad@saad:~$ python test.py "Mariam is a girl"
['Mariam', 'is', 'a', 'girl']

saad@saad:~$ python test.py
['Saad', 'is', 'a', 'boy']

But the simply running "test.py" gives:
Traceback (most recent call last):
  File "input_test.py", line 13, in 
x = sys.argv[1]
IndexError: list index out of range


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


Re: [Tutor] run with default value if input not given

2012-10-28 Thread Saad Javed
I've come up with this:

try:
sys.argv[1]
x = sys.argv[1]
main(x)
except IndexError:
main(x)

It works but seems hackish.

Saad

On Monday, October 29, 2012, Saad Javed wrote:

> Hi,
>
> #!/usr/bin/env python
>
> import sys
>
> x = 'Saad is a boy'
>
> def main(x):
> a = []
>  b = x.split(' ')
> for item in b:
> a.append(item)
>  print a
> if __name__ == '__main__':
> x = sys.argv[1]
>  main(x)
>
>
> How can I make this program run with the default value of x if I don't
> specify an argument at the command line?
> It should do this:
>
> saad@saad:~$ python test.py "Mariam is a girl"
> ['Mariam', 'is', 'a', 'girl']
>
> saad@saad:~$ python test.py
> ['Saad', 'is', 'a', 'boy']
>
> But the simply running "test.py" gives:
> Traceback (most recent call last):
>   File "input_test.py", line 13, in 
> x = sys.argv[1]
> IndexError: list index out of range
>
>
> Saad
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sending email via smtplib

2012-11-17 Thread Saad Javed
import smtplib

from_addr = "some_a...@hotmail.com"
to_addr = "some_a...@gmail.com"
smtp_srv = "smtp.live.com"

subject = "Test"
message = "Test"

msg = "To:%s\nFrom:%s\nSubject: %s\n\n%s" % (to_addr, from_addr, subject,
message)

smtp = smtplib.SMTP(smtp_srv, 587)
smtp.set_debuglevel(1)
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.login(user, passwd)
smtp.sendmail(from_addr, to_addr, msg)
smtp.quit()

When I run this code, I get this output:
send: 'ehlo [127.0.1.1]\r\n'
reply: '250-BLU0-SMTP190.blu0.hotmail.com Hello [my-ip-address]\r\n'
reply: '250-TURN\r\n'
reply: '250-SIZE 41943040\r\n'
reply: '250-ETRN\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-DSN\r\n'
reply: '250-ENHANCEDSTATUSCODES\r\n'
reply: '250-8bitmime\r\n'
reply: '250-BINARYMIME\r\n'
reply: '250-CHUNKING\r\n'
reply: '250-VRFY\r\n'
reply: '250-TLS\r\n'
reply: '250-STARTTLS\r\n'
reply: '250 OK\r\n'
reply: retcode (250); Msg: BLU0-SMTP190.blu0.hotmail.com Hello
[my-ip-address]
TURN
SIZE 41943040
ETRN
PIPELINING
DSN
ENHANCEDSTATUSCODES
8bitmime
BINARYMIME
CHUNKING
VRFY
TLS
STARTTLS
OK
send: 'STARTTLS\r\n'
Traceback (most recent call last):
  File "sendemail.py", line 24, in 
smtp.starttls()
  File "/usr/lib/python2.7/smtplib.py", line 636, in starttls
(resp, reply) = self.docmd("STARTTLS")
  File "/usr/lib/python2.7/smtplib.py", line 385, in docmd
return self.getreply()
  File "/usr/lib/python2.7/smtplib.py", line 358, in getreply
+ str(e))
smtplib.SMTPServerDisconnected: Connection unexpectedly closed: [Errno 104]
Connection reset by peer

I can send email via browser. Why is my authentication being blocked by
hotmail?

P.S: I tried sending from gmail. Same error.

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


Re: [Tutor] sending email via smtplib

2012-11-18 Thread Saad Javed
I don't think using SSL works with hotmail. I tried using:

smtplib.*SMTP_SSL*("smtp.live.com", 587)
smtplib.login(user, passwd)
...

That gave this error:

Traceback (most recent call last):
  File "sendemail.py", line 22, in 
smtp = smtplib.SMTP_SSL(smtp_srv, 587)
  File "/usr/lib/python2.7/smtplib.py", line 776, in __init__
SMTP.__init__(self, host, port, local_hostname, timeout)
  File "/usr/lib/python2.7/smtplib.py", line 249, in __init__
(code, msg) = self.connect(host, port)
  File "/usr/lib/python2.7/smtplib.py", line 309, in connect
self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python2.7/smtplib.py", line 782, in _get_socket
new_socket = ssl.wrap_socket(new_socket, self.keyfile, self.certfile)
  File "/usr/lib/python2.7/ssl.py", line 381, in wrap_socket
ciphers=ciphers)
  File "/usr/lib/python2.7/ssl.py", line 143, in __init__
self.do_handshake()
  File "/usr/lib/python2.7/ssl.py", line 305, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [Errno 1] _ssl.c:504: error:140770FC:SSL
routines:SSL23_GET_SERVER_HELLO:unknown protocol
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sending email via smtplib

2012-11-19 Thread Saad Javed
Using port 25 with SMTP_SSL gives:

Traceback (most recent call last):
  File "sendemail.py", line 22, in 
smtp = smtplib.SMTP_SSL(smtp_srv, 25)
  File "/usr/lib/python2.7/smtplib.py", line 776, in __init__
SMTP.__init__(self, host, port, local_hostname, timeout)
  File "/usr/lib/python2.7/smtplib.py", line 249, in __init__
(code, msg) = self.connect(host, port)
  File "/usr/lib/python2.7/smtplib.py", line 309, in connect
self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python2.7/smtplib.py", line 782, in _get_socket
new_socket = ssl.wrap_socket(new_socket, self.keyfile, self.certfile)
  File "/usr/lib/python2.7/ssl.py", line 381, in wrap_socket
ciphers=ciphers)
  File "/usr/lib/python2.7/ssl.py", line 143, in __init__
self.do_handshake()
  File "/usr/lib/python2.7/ssl.py", line 305, in do_handshake
self._sslobj.do_handshake()
socket.error: [Errno 104] Connection reset by peer
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] stop a loop after precise amount of time

2012-11-25 Thread Saad Javed
import time

s = time.time() + 30
running = True
while running:
if time.time() == s:
print 'yes'
running = False

This stops the loop after 30s but the program uses about 12% cpu. What
would be a more efficient way to do this? (p.s. i'm on python 2.7.3)

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


Re: [Tutor] stop a loop after precise amount of time

2012-11-25 Thread Saad Javed
time.sleep(30) will pause the program for 30s. I want to the run the
program for 30s.

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


Re: [Tutor] stop a loop after precise amount of time

2012-11-25 Thread Saad Javed
import time

running = True
while running:
print 'yes'
time.sleep(10)

This will print 'yes' after every 10s. I want to print 'yes' for 10s, then
quit.

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


Re: [Tutor] creating dictionary from a list

2013-04-13 Thread Saad Javed
What just happened here? :)

I am trying to learn python so i'm sorry if my mistakes seem trivial.

On Saturday, April 13, 2013, Mark Lawrence wrote:

> On 13/04/2013 15:34, Saad Bin Javed wrote:
>
>> I ran into a bit of problem with my revised code based on Steven's
>> suggestions.
>>
>> lst = ['', 'Thu Apr 04   Weigh In', '', 'Sat Apr 06 Collect
>> NIC', ' Finish PTI Video', '', 'Wed Apr 10  Serum
>> uric acid test', '', 'Sat Apr 13   1:00pm  Get flag from dhariwal', '',
>> 'Sun Apr 14  Louis CK Oh My God', '', '']
>>
>> lst = filter(None, lst)
>> lst = [item.split('  ') for item in lst]
>> lst = [item for sublist in lst for item in sublist]
>> lst = filter(None, lst)
>>
>> This code would produce:
>>
>> ['Thu Apr 04', ' Weigh In', 'Sat Apr 06', ' Collect NIC', ' Finish PTI
>> Video', 'Wed Apr 10', ' Serum uric acid test', 'Sat Apr 13', ' 1:00pm',
>> 'Get flag from dhariwal', 'Sun Apr 14', ' Download Louis CK Oh My God']
>>
>> dict = {}
>> for item in lst:
>>  if item.startswith(('Mon','Tue','**Wed','Thu','Fri','Sat','Sun'))**:
>>
>>  dict.update({lst[lst.index(**item)].lstrip():
>> lst[lst.index(item)+1].lstrip(**)})
>> print dict
>>
>> Such a dictionary would only add the item next to the date as the value.
>> But from the list you can see 'Sat Apr 06' has two items on the agenda
>> while 'Sat Apr 13' show item and a time. So you can understand why such
>> a dict would be useless.
>>
>> I want all agenda items joined as a comma delimited string and added to
>> the date key as a value. I've been mulling over how to go about it. One
>> idea was to get indices of dates in the list and add all items in
>> between them as values.
>>
>> index_keys = [] #0, 2, 5, 7, 9
>> index_values = [] #1, 3, 4, 6, 8, 10
>> for item in lst:
>>  if
>> item.lstrip().startswith(('**Mon','Tue','Wed','Thu','Fri','**
>> Sat','Sun')):
>>  index_keys.append(lst.index(**item))
>>  else:
>>  index_values.append(lst.index(**item))
>>
>> But I can't quite get it to understand that i want all items between
>> position 0 and 2 in the list to be assigned to item at 0 in the
>> dictionary and so forth.
>>
>> Ideas?
>>
>>
> Don't fight Python, unlike this chap[1] :)  Basically if you're looping
> around any data structure you rarely need to use indexing, so try this
> approach.
>
> for item in lst:
> if item.startswith(('Mon','Tue','**Wed','Thu','Fri','Sat','Sun'))**:
> myDict[item] = []
> saveItem = item
> else:
> myDict[saveItem].append(item.**strip())
>
>
> [1]http://www.bbc.co.uk/news/**world-us-canada-22118773
>
> --
> If you're using GoogleCrap™ please read this http://wiki.python.org/moin/*
> *GoogleGroupsPython .
>
> Mark Lawrence
>
> __**_
> 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] creating dictionary from a list

2013-04-13 Thread Saad Javed
>
> Don't fight Python, unlike this chap[1] :)  Basically if you're looping
> around any data structure you rarely need to use indexing, so try this
> approach.
>
> for item in lst:
> if item.startswith(('Mon','Tue','**Wed','Thu','Fri','Sat','Sun'))**:
> myDict[item] = []
> saveItem = item
> else:
> myDict[saveItem].append(item.**strip())
>

This creates a dictionary whose keys are out of order in terms of dates.

{'Thu Apr 04': ['Weigh In'], 'Sat Apr 06': ['Collect NIC', 'Finish PTI
Video'], 'Wed Apr 10': ['Serum uric acid test'], 'Sun Apr 14': ['Download
Louis CK Oh My God', '4:00pm', 'UPS Guy'], 'Sat Apr 13': ['1:00pm', 'Get
flag from dhariwal']}

Sat Apr 13 is appearing after Sun Apr 14. How do you sort this?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating dictionary from a list

2013-04-13 Thread Saad Javed
> for item in lst:
>>  if
>> item.startswith(('Mon','Tue','**__Wed','Thu','Fri','Sat','Sun'**))__:
>>  myDict[item] = []
>>  saveItem = item
>>  else:
>>  myDict[saveItem].append(item._**_strip())
>>
>> Returns:
 File "gcalcli_agenda_test.py", line 38
if item.startswith(('Mon','Tue','__Wed','Thu','Fri','Sat','Sun'))__:
  ^
SyntaxError: invalid syntax
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating dictionary from a list

2013-04-13 Thread Saad Javed
I don't know what I'm doing wrong here. Ive tried copy-pasting the line.
I've tried entering underscores manually. doesn't work.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating dictionary from a list

2013-04-14 Thread Saad Javed
Steven,

You're right about Mark's email. I didn't get the humor and thought the
remark was kinda tough on me. You correctly pointed out his intent. So my
apologies to Mark.

As for the underscores, what happened is that *I didn't voluntarily add the
underscores to begin with. *If you read the emails again, after Mark's
answer about not looping, I asked that the dictionary created as a result
of his code wasn't ordered. In reply, he sent me a portion of his previous
email containing underscores before Wed (__Wed)! I thought it was the
strange but since I'm a beginner, I copied the code and applied it which of
course threw up a syntax error. What I wanted to ask Mark was that *why* had
*he* added underscores because they were throwing up errors for me. He kept
pointing me to his earlier email and asking me compare my line with his
line and I'll find out what the problem is.

In my mind, I thought I was not entering the underscores correctly or at
the right position. As you have explained it turns out it was the email
client which was adding stuff on its own. It added the underscores to
Mark's first response to my dictionary order question and I took it as *Mark's
answer.*

Regards,

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


Re: [Tutor] adding users to tweets on a list

2013-08-06 Thread Saad Javed
> It looks like you're using Python 2, but you didn't specify.
>
> I'd probably do something like this:
>
> #!/usr/bin/env python
>
> MAX_LENGTH = 140
>
> users = [
> "saad", "asad", "sherry", "danny", "ali", "hasan", "adil",
> "yousaf",
> "maria", "bilal", "owais",
> ]
>
> def populate():
> message = raw_input("Enter string: ")
> while users:
> new_message = " ".join([message, "@" + users.pop(0)])
> if len(new_message) > MAX_LENGTH:
> break
> message = new_message
> return message
>
> if __name__ == "__main__":
> print(populate())
>

It will add max no. of  users to one tweet until limit is reached. I want
all users added to the tweet. E.g. if 4 users can be added to the tweet
before reaching the limit, return three tweets...first two with 4 users
attached and the last one with three. Think of it as sending the same tweet
with all the users in the list mentioned. The code I posted does that but
can only add 3 users at a time. I want it to be able to calculate maximum
no of users it can attach to the tweet and then keep doing it until the
list runs out. Hope i've explained my problem. And yes, i'm using python 2.

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


Re: [Tutor] adding users to tweets on a list

2013-08-06 Thread Saad Javed
> Ah, I see. Sorry, I misread your requirements. Something like this should
> work.
>
> #!/usr/bin/env python
>
> MAX_LENGTH = 140
>
>
> class TweetTooLongError(Exception):
> """
> Raised when a user would be too long to add to the tweet, even
> alone.
> """
> pass
>
>
> def generate_tweets(message, users):
> """
> Generate tweets based around a message, with users
> appended to each tweet.
>
> :param message: the base message
> :param users: a group of users to append
> :returns: tweets based around the message to the users
> """
>
> add = ""
> longest_in_list = " @" + max(users, key=len)
>
> if len(longest_in_list) + len(message) > MAX_LENGTH:
> raise TweetTooLongError(
> "At least one user would make the tweet too long."
> )
>
> while users:
> new_message = message
> while len(new_message) + len(add) <= MAX_LENGTH:
> new_message += add
> if not users:
> break
> add = " @" + users.pop(0)
> yield new_message
>
>
> if __name__ == "__main__":
> users = [
> "saad", "asad", "sherry", "danny", "ali", "hasan", "adil",
> "yousaf", "maria", "bilal", "owais",
> ]
> message = raw_input("Enter string: ")
> print("\n".join(generate_tweets(message, users)))
>

Thank you for your response. This code has a bug.

If there is one user left in the user list, it doesn't print a tweet with
just that one user added. For example use this string: "These are my
friends living in the same city as i am. I have known them for years. They
are good people in general. They are:"...you will see that "owais" is still
in the list and is not added to a new tweet and printed.

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


Re: [Tutor] adding users to tweets on a list

2013-08-06 Thread Saad Javed
> ...or, better, remove the if...break and just do:
>
> while users and len(new_message) + len(add) <= MAX_LENGTH:
>

That causes:

Enter string: These are my friends living in the same city as i am. I have
known them for years. They are good people in general. They are:
Traceback (most recent call last):
  File "chris_tweet_len.py", line 44, in 
print("\n".join(generate_tweets(message, users)))
  File "chris_tweet_len.py", line 31, in generate_tweets
while users and len(new_message) + len(add) <= MAX_LENGTH:
UnboundLocalError: local variable 'new_message' referenced before assignment

And the earlier fix now adds two users to a tweet, then one user, then two
user, then one... :(
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] adding users to tweets on a list

2013-08-06 Thread Saad Javed
>
> And the earlier fix now adds two users to a tweet, then one user, then two
> user, then one... :(
>

Enter string: These are my friends living in the same city as i am. I have
known them for years. They are good people in general. They are:
These are my friends living in the same city as i am. I have known them for
years. They are good people in general. They are: @saad @asad
These are my friends living in the same city as i am. I have known them for
years. They are good people in general. They are: @sherry
These are my friends living in the same city as i am. I have known them for
years. They are good people in general. They are: @danny @ali
These are my friends living in the same city as i am. I have known them for
years. They are good people in general. They are: @hasan @adil
These are my friends living in the same city as i am. I have known them for
years. They are good people in general. They are: @yousaf
These are my friends living in the same city as i am. I have known them for
years. They are good people in general. They are: @maria @bilal
These are my friends living in the same city as i am. I have known them for
years. They are good people in general. They are: @owais
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] adding users to tweets on a list

2013-08-06 Thread Saad Javed
> I don't see how that differs from your expected output...?
>
> > I want all users added to the tweet. E.g. if 4 users can be added to the
> > tweet before reaching the limit, return three tweets...first two with 4
> users
> > attached and the last one with three.
>
> You hit the 140 character limit if another user is added, so it resets to
> the
> base message and adds the next user(s) as possible.
>
> What is your expected output for that sample input?
>

Oops! My bad. The fix worked as expected. The output fooled me into
thinking it was skipping a user every second line. Actually MAX_LENGTH was
being reached in each case. I'll check the tweet.py you posted.

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


Re: [Tutor] adding users to tweets on a list

2013-08-06 Thread Saad Javed
I added *len(new_message) + len(add) <= MAX_LENGTH *to the outer while loop
instead of inner which threw an error. Your code works as expected. Thanks
a lot!

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


Re: [Tutor] adding users to tweets on a list

2013-08-07 Thread Saad Javed
There was only Chris responding to the question so I removed the line above
the quoted part in my responses that says "On Aug 6, 2013 11:36 PM, "Dave
Angel"  wrote:"... is that what's confusing?
On Aug 6, 2013 11:36 PM, "Dave Angel"  wrote:

> Saad Javed wrote:
>
> > I want to add users to the tweet from the list, the no. of users added
> > based on the length of the tweet.
> >
> This version should be a bit cleaner than what I've seen on this thread.
>
> #!/usr/bin/env python
>
> LIMIT = 140
> #(I use uppercase there to show it's a constant)
>
> def send(message, users):
> output = message
> while users:
> while users and 1+len(output+users[0]) < LIMIT:
> output += " " + users.pop(0)
> if output == message:
> print "message too long for user", user[0]
> raise userError
> print output
> output = message
>
> lst = ['@saad', '@asad', '@sherry', '@danny', '@ali', '@hasan',
> '@adil', '@yousaf', '@maria', '@bilal', '@owais']
>
>
> #string = raw_input('enter string: ')
> #example string
> string = ("These are my friends living in the same city as i am."
> " I have known them for years. They are "
> "good people in general. They are:")
>
> send(string, lst)
>
> BTW, you have a bunch of other messages on the thread which are replying
> to the invisible man, posts that aren't (yet?) visible.  Since you quote
> him without attribution, we have no clue who you're commenting about.
>
> --
> DaveA
>
>
> ___
> 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] adding users to tweets on a list

2013-08-07 Thread Saad Javed
On Wednesday, August 7, 2013, Alan Gauld wrote:

> On 07/08/13 15:41, Saad Javed wrote:
>
>> There was only Chris responding
>>
>
> Apparently he didn't CC the list so the rest of us didn't see it(*).
>
>  is that what's confusing?
>>
>
> It's not just the lack of attribution but the fact we just didn't see the
> post to which you are replying.
>
> (*)It is possible that Chris' mail is in the moderation queue,
> which I was hoping to visit tonight or tomorrow...
> In which case, watch this space...
>
>
Chris has been emailing me directly. Thats why his responses are not
showing up in the conversation.
Dear Chris, please remember to send your replies to tutor@python.org with
the subject of the question ("adding users to tweets on a list"), so that
others can see them.

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


Re: [Tutor] adding users to tweets on a list

2013-08-07 Thread Saad Javed
On Thursday, August 8, 2013, Chris Down wrote:

> On 2013-08-08 02:40, Saad Javed wrote:
> > Chris has been emailing me directly. Thats why his responses are not
> > showing up in the conversation.
> > Dear Chris, please remember to send your replies to 
> > tutor@python.orgwith
> > the subject of the question ("adding users to tweets on a list"), so that
> > others can see them.
>
> You are mistaken, python-tutor was Cc'd on every message. I was merely
> held in
> the moderation queue -- there is nothing I can do about that.
>

My mistake, I apologize. I did the same thing a while back by accident and
assumed you made the same mistake. I guess it must be the moderation queue
then. It has reinforced my long standing belief that most programmers are
smarter than I am ;)

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