Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50906 > unrolled thread
| Started by | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| First post | 2013-07-19 10:21 -0400 |
| Last post | 2013-07-20 09:04 +1000 |
| Articles | 4 — 4 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Share Code Tips Joel Goldstick <joel.goldstick@gmail.com> - 2013-07-19 10:21 -0400
Re: Share Code Tips Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-19 16:19 +0000
Re: Share Code Tips Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-19 18:10 -0400
Re: Share Code Tips Chris Angelico <rosuav@gmail.com> - 2013-07-20 09:04 +1000
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2013-07-19 10:21 -0400 |
| Subject | Re: Share Code Tips |
| Message-ID | <mailman.4870.1374243674.3114.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
On Fri, Jul 19, 2013 at 9:51 AM, Devyn Collier Johnson <
devyncjohnson@gmail.com> wrote:
> Aloha Python Users!
>
> I have some coding tips and interesting functions that I want to share
> with all of you. I want to give other programmers ideas and inspiration. It
> is all Python3; most of it should work in Python2. I am a Unix/Linux
> person, so some of these will only work on Unix systems. Sorry Microsuck
> users :-D ;-)
>
> All of the below Python3 code came from Neobot v0.8dev. I host an
> artificial intelligence program on Launchpad (LP Username:
> devyncjohnson-d). I have not released my Python version yet. The current
> version of Neobot (v0.7a) is written in BASH and Python3.
>
> To emulate the Linux shell's date command, use this Python
>
> function def DATE(): print(time.strftime("%a %B %d %H:%M:%S %Z %Y"))
>
> Want an easy way to clear the terminal screen? Then try this:
>
> def clr(): os.system(['clear','cls'][os.**name <http://os.name> == 'nt'])
>
> Here are two Linux-only functions:
>
> def GETRAM(): print(linecache.getline('/**proc/meminfo',
> 1).replace('MemTotal:', '').strip()) #Get Total RAM in kilobytes#
> def KDE_VERSION(): print(subprocess.getoutput('**kded4 --version | awk
> -F: \'NR == 2 {print $2}\'').strip()) ##Get KDE version##
>
> Need a case-insensitive if-statement? Check this out:
>
> if 'YOUR_STRING'.lower() in SOMEVAR.lower():
>
> Have a Python XML browser and want to add awesome tags? This code would
> see if the code to be parsed contains chess tags. If so, then they are
> replaced with chess symbols. I know, many people hate trolls, but trolls
> are my best friends. Try this:
>
> if '<chess_'.lower() in PTRNPRS.lower(): DATA =
> re.sub('<chess_white_king/>', '♔', PTRNPRS, flags=re.I); DATA =
> re.sub('<chess_white_queen/>', '♕', DATA, flags=re.I); DATA =
> re.sub('<chess_white_castle/>'**, '♖', DATA, flags=re.I); DATA =
> re.sub('<chess_white_bishop/>'**, '♗', DATA, flags=re.I); DATA =
> re.sub('<chess_white_knight/>'**, '♘', DATA, flags=re.I); DATA =
> re.sub('<chess_white_pawn/>', '♙', DATA, flags=re.I); DATA =
> re.sub('<chess_black_king/>', '♚', DATA, flags=re.I); DATA =
> re.sub('<chess_black_queen/>', '♛', DATA, flags=re.I); DATA =
> re.sub('<chess_black_castle/>'**, '♜', DATA, flags=re.I); DATA =
> re.sub('<chess_black_bishop/>'**, '♝', DATA, flags=re.I); DATA =
> re.sub('<chess_black_knight/>'**, '♞', DATA, flags=re.I); PTRNPRS =
> re.sub('<chess_black_pawn/>', '♟', DATA, flags=re.I)
>
> For those of you making scripts to be run in a terminal, try this for a
> fancy terminal prompt:
>
> INPUTTEMP = input('User ≻≻≻')
>
>
> I may share more code later. Tell me what you think of my coding style and
> tips.
>
>
> Mahalo,
>
> Devyn Collier Johnson
> DevynCJohnson@Gmail.com
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>
I'm guessing you may be posting with html. So all your code runs together.
--
Joel Goldstick
http://joelgoldstick.com
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-07-19 16:19 +0000 |
| Message-ID | <51e966f4$0$29971$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #50906 |
On Fri, 19 Jul 2013 10:21:10 -0400, Joel Goldstick wrote: > <div dir="ltr"><br><div class="gmail_extra"><br><br><div > class="gmail_quote"> [snip 70-odd lines of HTML...] > I'm guessing you may be posting with html. So all your code runs > together. > <br clear="all"></div><div class="gmail_extra"><br>-- <br><div > dir="ltr"> <div>Joel Goldstick<br></div><a href="http:// > joelgoldstick.com" target="_blank">http://joelgoldstick.com</a> > <br></div> </div></div> My irony meter didn't merely explode, it actually vaporized. -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Devyn Collier Johnson <devyncjohnson@gmail.com> |
|---|---|
| Date | 2013-07-19 18:10 -0400 |
| Message-ID | <mailman.4886.1374271811.3114.python-list@python.org> |
| In reply to | #50913 |
On 07/19/2013 12:19 PM, Steven D'Aprano wrote: > On Fri, 19 Jul 2013 10:21:10 -0400, Joel Goldstick wrote: > >> <div dir="ltr"><br><div class="gmail_extra"><br><br><div >> class="gmail_quote"> > [snip 70-odd lines of HTML...] > >> I'm guessing you may be posting with html. So all your code runs >> together. >> <br clear="all"></div><div class="gmail_extra"><br>-- <br><div >> dir="ltr"> <div>Joel Goldstick<br></div><a href="http:// >> joelgoldstick.com" target="_blank">http://joelgoldstick.com</a> >> <br></div> </div></div> > > My irony meter didn't merely explode, it actually vaporized. > > > What is the issue with my email? Should I resend it? Mahalo, DCJ
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-07-20 09:04 +1000 |
| Message-ID | <mailman.4889.1374275088.3114.python-list@python.org> |
| In reply to | #50913 |
On Sat, Jul 20, 2013 at 8:10 AM, Devyn Collier Johnson <devyncjohnson@gmail.com> wrote: > > On 07/19/2013 12:19 PM, Steven D'Aprano wrote: >> >> On Fri, 19 Jul 2013 10:21:10 -0400, Joel Goldstick wrote: >> >>> <div dir="ltr"><br><div class="gmail_extra"><br><br><div >>> class="gmail_quote"> >> >> [snip 70-odd lines of HTML...] >> >>> I'm guessing you may be posting with html. So all your code runs >>> together. >>> <br clear="all"></div><div class="gmail_extra"><br>-- <br><div >>> dir="ltr"> <div>Joel Goldstick<br></div><a href="http:// >>> joelgoldstick.com" target="_blank">http://joelgoldstick.com</a> >>> <br></div> </div></div> >> >> >> My irony meter didn't merely explode, it actually vaporized. >> >> >> > What is the issue with my email? Should I resend it? Either your lines are insanely long (and got wrapped by the mailer), or your multi-line functions lost their internal line breaks. Joel suggested that you may have been posting HTML mail (you're not), implying that it's worse than plain text mail (it is), and himself posted in HTML (that's irony). ChrisA (This is a parenthesis.)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web