finding file

2006-06-05 Thread su
Hi , I am trying to understand myself with some basic programs in
python, I have written a small script to search for core files in the
current dir. but when i tried to execute, it is searching the core
files in the subdir also. could someone help me on how can i restrict
my code to search the file in the current dir only

import os, os.path
import re
def core_finder(arg, dir, files):
for file in files:
path = os.path.join (dir, file)
if re.search("core.*", path):
   print "found"
   print path


os.path.walk('.', core_finder, 0)

-- 
http://mail.python.org/mailman/listinfo/python-list


is it possible to find which process dumped core

2006-06-05 Thread su
to find which process dumped core at the promt we give

$ file core.28424

core.28424: ELF 32-bit LSB core file of 'soffice.bin' (signal 11),
Intel 80386, version 1 (SYSV), from 'soffice.bin'

from this command we know 'soffice.bin' process dumped core. Now can i
do the same using python i.e. finding which process dumped core?  if so
how can i do it?

-- 
http://mail.python.org/mailman/listinfo/python-list


write()

2011-08-22 Thread Hyun-su
Hi,
I have a file which is 3D data ([pixel_x, pixel_y, pixel_z])

I want to plot and write into other file as 1 dimension ([:, y_cut,
z_cut])

How can I do it?

-- 
http://mail.python.org/mailman/listinfo/python-list


how to apply "mvc" pattern to gui-design in python

2005-03-28 Thread Su Wei
i have a project want to  develop with python.
who can tell me that how to apply "mvc" pattern to gui-design in python.
please give me some advices!
ths in advanced.


-- 
蓦然回首曾经岁月,
朦胧中依稀闪烁着清晰。
才发现,
原来在我的记忆深处,
还残留着宁静而又幸福的瞬间。

一世风流已飘过,转眼渐成白头翁。
--
http://mail.python.org/mailman/listinfo/python-list


why and when we should do it?

2005-03-29 Thread Su Wei
hi,everybody,Sorry to bother you. 
i hvae seen some code like this before:

class BusinessBO :
dev __init__(slef):
#write you own code here
dev businessMethod :
#write you own code here
pass

why and when we should add the keyword "pass" ?

and some time i have seen

class SomeObject(Object) :
  #some code

why and when we should inherit Object?

thanks in advanced.


-- 
蓦然回首曾经岁月,
朦胧中依稀闪烁着清晰。
才发现,
原来在我的记忆深处,
还残留着宁静而又幸福的瞬间。

一世风流已飘过,转眼渐成白头翁。
--
http://mail.python.org/mailman/listinfo/python-list


Should a beginner do some coding excises? How can I find the sources?

2011-09-12 Thread sillyou su
I'm reading "Learning Python"( Chinese version). Before I go through
the whole book, I want to do some excises matching each charter.
Any tips? Any better advice?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Should a beginner do some coding excises? How can I find the sources?

2011-09-13 Thread sillyou su
On Sep 13, 1:14 pm, memilanuk  wrote:
> On 09/12/2011 09:20 PM, sillyou su wrote:
>
> > I'm reading "Learning Python"( Chinese version). Before I go through
> > the whole book, I want to do some excises matching each charter.
> > Any tips? Any better advice?
>
> For the code examples, have you tried looking up the home page for the
> book?  Google for 'oreilly learning python' and find the correct edition
> that you have.
>
> If its the 4th ed (current), you should end up on a page like this:
>
> http://shop.oreilly.com/product/9780596158071.do
>
> Down in the right hand side-bar, there should be a menu 'Essential
> Links' and one of the options is 'Download code' or something along
> those lines.  The link should take you to a zip file with all the code
> examples in the book.
>
> As far as practice exercises... maybe something like
> codingbat.com/python would be helpful.  Its not related to the book at
> all, and doesn't go nearly as in depth... but its kind of neat to play
> with and see how your code works when someone else is grading it! (at
> least for me).
>
> HTH,
>
> Monte

codingbat.com/python!
The website is really interesting.
Thank you!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: To start a simple server

2011-10-03 Thread sillyou su
I am running web.py on my computer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: To start a simple server

2011-10-03 Thread sillyou su
On Oct 4, 2:15 am, Amelia T Cat  wrote:
> On Mon, 03 Oct 2011 10:09:59 -0700, sillyou su wrote:
> > 啊!!
>
> > I should use 127.0.0.1 instance of  0.0.0.0
>
> Theoretically either one should be fine. If you use 127.0.0.1 it will
> only expose the service to your local machine. If you use 0.0.0.0 ut will
> expose the service to other computers on the same network as the one
> running the service.

Yes. Thank you.

I run  service on my computer. So I should use localhost to launch the
service.

-- 
http://mail.python.org/mailman/listinfo/python-list


Weird behavior in search in a list

2007-03-29 Thread Su Y
hi all,
I can't understand how this code work, its behavior is really weird
for me...

I want find the first number in extend[] which is larger than num, so
I wrote:
def find(num):
count=0
for elem in extend:
if elem-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Weird behavior in search in a list

2007-03-29 Thread Su Y
On 3月29日, 下午7时51分, "Su Y" <[EMAIL PROTECTED]> wrote:
> hi all,
> I can't understand how this code work, its behavior is really weird
> for me...
>
> I want find the first number in extend[] which is larger than num, soI wrote:
>
> def find(num):
> count=0
> for elem in extend:
> if elem count+=1
> return count
>
> I found that if extend[] is monotonous, like [1.1, 2.3, 3.2, 4.5,
> 5.6],
> it works fine: find(4) returns 3, extend[3] is 4.5.
> But, if extend[] is not monotonous, like [1.1, 2.3, 3.2, 4.5, 5.6,
> 4.6, 3.4, 2.1, 0.3],
> find(4) returns 6, extend[6] is 3.4!
>
> what's going on here? I really can't understand

and I am using Python 2.5 on WinXP.

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Weird behavior in search in a list

2007-03-29 Thread Su Y
On 3月29日, 下午8时22分, Michael Bentley <[EMAIL PROTECTED]> wrote:
> On Mar 29, 2007, at 6:51 AM, Su Y wrote:
>
>
>
>
>
> > I want find the first number in extend[] which is larger than num, so
> > I wrote:
> > def find(num):
> > count=0
> > for elem in extend:
> > if elem > count+=1
> > return count
>
> > I found that if extend[] is monotonous, like [1.1, 2.3, 3.2, 4.5,
> > 5.6],
> > it works fine: find(4) returns 3, extend[3] is 4.5.
> > But, if extend[] is not monotonous, like [1.1, 2.3, 3.2, 4.5, 5.6,
> > 4.6, 3.4, 2.1, 0.3],
> > find(4) returns 6, extend[6] is 3.4!
>
> > what's going on here? I really can't understand
>
> find() loops through the list, and every time it finds a value less
> than num it increments count.  So in your second example the values
> 1.1, 2.3, 3.2,  3.4, 2.1, and 0.3 are all less than 4, which means
> count will be 6.
>
> As you learned, a sorted list behaves as you expect.  So one approach
> is to sort your list first.  But another perhaps better approach is
> to do something like:
>
> def find(num):
> # check to make sure there *is* a value greater than num
> if max(extend) > num:
> # then return the smallest value that is greater than num
> return min([x for x in extend if x > num])
> else:
> return None
>
> Hope this helps,
> Michael

oh yes, it's the "break" I forgot... Thank you, it helps me a lot!

-- 
http://mail.python.org/mailman/listinfo/python-list

Chinese character become ??? by pymssql or pyodbc

2008-04-14 Thread James Su
I tried to use pymssql to access MSSQL 2000, with a table, I store
Chinese Character in NVarchar field, Chinese Character display
normally when I query them by MS SQL Query Analyzer under Windows or
by unixODBC under Ubuntu.
But when I query those data by pymssql or pyodbc, all Chinese
Character display ??? instead.
Does anyone has some advice or thread? Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


directory listing

2005-11-11 Thread SU News Server
I've struggled with this for quite a while and I'm am just not sure 
what is going on. I have the following code
import os

def buildList( directory='/Users/mkonrad' )

dirs = [ ]

listing = os.listdir(directory)

   for x in listing:
  if os.path.isdir(x):
dirs.append(x)

return dirs

This always returns an empty list.
Now if I change it so that directory='.' or directory=os.getcwd()
Then it returns a list of directories. 

Any ideas?

Thank you,
-Michael




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to handle exceptions properly in a pythonic way?

2015-11-04 Thread tian . su . yale
在 2015年11月4日星期三 UTC-6下午10:18:33,[email protected]写道:
> > Which would you prefer?
> 
> So if I am just checking for the ConnectionError in get_html and a new 
> exception arises, I will have traceback to the get_html function showing that 
> unhandled exception has happened.
> Now I have to put additional exception block for managing the new exception 
> in the get_html function and I am covered.
> 
> Is that what you wanted to say?

Hi,
If I may, I feel you are trying to address a few separate questions, although 
they do relate to each other.
1. Coding Design: with the try/except block inside or outside the function
2. Exception Handling: What to do with new un-anticipated exceptions
3. How to record the exception for reference: logging or special value

My feeling is:
1. Personally prefer to put try/except block outside the function, to keep the 
code clean and easy to follow.
2. I would suggest follow the Test Driven Development (TDD) approach. You are 
not able to anticipate all types of possible exceptions. However, I'm sure you 
have a pretty good idea about what exceptions are more likely to happen and 
cause you problem. In that case, just develop your code to pass these tests, 
and refactor it in the future if really needed. Not necessary to push your code 
to be perfect, able to handle every possible exception.
3. Kind of personal choice here, since no matter which way you go, you do need 
to follow it up and deal with them. Probably I would log it just for record 
keeping purpose. As long as you follow up and trace back to the root cause, 
they seem to serve the same goal.
Hope this helps...
All the best,
Tian
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to handle exceptions properly in a pythonic way?

2015-11-04 Thread tian . su . yale
Hi,
If I may, I feel you are tying to address a few questions at the same time, 
although they are related
1. Where to put the try/except block, inside or outside the function
2. How to deal with un-anticipated exceptions
3. How to keep record
My personal feelings are:
1. Kind of prefer try/except block outside the function though. This way it 
looks clean and easy to follow. In terms of logging the url, since you pass it 
to the function anyway, there should be ways to keep this option, even with the 
block written outside the function.
2. From code development perspective, would suggest you follow Test Driven 
Development (TDD) approach. Nobody can anticipate all of the possible outcomes, 
but I'm sure you have a pretty good idea about the most likely scenarios, and 
just make sure that your code is suitable for these scenarios. When future new 
exceptions arise, you can always refactor your code as needed.
3. Feel it's a personal choice here as being pointed out earlier. No mater 
which way you go, you just have to follow it up and deal with it, trace it back 
to the root cause. I kind of prefer logging, so to keep a good record for 
myself, and you can make it very informative.
Hope this helps.
All the best,
Tian
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: raw_input and break

2015-11-04 Thread tian . su . yale
在 2015年11月4日星期三 UTC-6下午3:45:09,input/[email protected]写道:
> I have an continues loop with "while True:"
> Now I want to use "raw_input" and when I press "s" on the keybord that it 
> will 
> "break" the continues loop.
> 
> I tried:
> choices = raw_input
> if choises == s:
> break
> 
> But even when I not press "s" it "break"
> I want that I not press "s" the script continues.
> 
> Any ideas ?
> 
> Thanks
> 
> 
> 
> -- 
> - --- -- -
> Posted with NewsLeecher v7.0 Beta 2
> Web @ http://www.newsleecher.com/?usenet
> --- -  -- -

while True:
inp = input("Enter whatever you want, letter 's' to stop: ")
if inp == 's':
print("Program stopped.")
break
print("You just entered:", inp)

Is this along the line that you are thinking? As pointed out earlier, it will 
be much easier for people to help if you can share the exact code you put into 
and the error messages as well. Thanks and good luck!
All the best,
Tian
-- 
https://mail.python.org/mailman/listinfo/python-list