Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.python > #4645

Re: [Python-de] Wie sieht Python fuer mich aus?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From "Sven R. Kunze" <srkunze@mail.de>
Newsgroups de.comp.lang.python
Subject Re: [Python-de] Wie sieht Python fuer mich aus?
Date Mon, 9 Jan 2017 21:44:50 +0100
Lines 75
Message-ID <mailman.407.1483994693.2395.python-de@python.org> (permalink)
References <Python-20170108184230@ram.dialup.fu-berlin.de> <3dee2ce4-274a-3b59-756c-3559e7c568c1@mail.de> <mailman.382.1483969007.2395.python-de@python.org> <edhsa2F4aukU1@mid.individual.net> <cc585ec8-d4b4-685b-0a1d-ef62327c0e96@mail.de> <mailman.401.1483983912.2395.python-de@python.org> <edi2t2F5vcjU1@mid.individual.net> <6c4f418c-b74a-9968-82e9-a4eb45ca1237@mail.de> <mailman.405.1483988893.2395.python-de@python.org> <edi8c5F7b3eU1@mid.individual.net> <0c0ce991-1e48-dd0e-9959-0ec3b22b4e0e@mail.de>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de dxtO+LeJTgboznzFjAWG+gAGf9kk2A0sO7VCbmHTstmQ==
Return-Path <srkunze@mail.de>
X-Original-To python-de@python.org
Delivered-To python-de@mail.python.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mailde201610; t=1483994691; bh=3A6N64PSNvvmsVG1oGau+H4c4yepohPCQmxhKG8eAWs=; h=Subject:To:References:From:Date:In-Reply-To:From; b=XYD0TO5r+w8MVo8rgO0lfkw1ghrD4BzBVa8IiurR3ObGVfrAwVJHkVrZGkNWJdVzA tlf3jyV/CgqrlC04vhjDmYpAhUW8WlGHcZpLTWexswZOlny3cCa5+WfL+Qn4a4KCe4 jBa4QlsDP36dLeq2NNsIdNJ6kVOAoUpLhxdsOFY0=
In-Reply-To <edi8c5F7b3eU1@mid.individual.net>
X-purgate clean
X-purgate This mail is considered clean (visit http://www.eleven.de for further information)
X-purgate-type clean
X-purgate-Ad Categorized by eleven eXpurgate (R) http://www.eleven.de
X-purgate This mail is considered clean (visit http://www.eleven.de for further information)
X-purgate clean
X-purgate-size 5575
X-purgate-ID 154282::1483994691-00000CF2-D544B17B/0/0
X-Content-Filtered-By Mailman/MimeDel 2.1.23
X-BeenThere python-de@python.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Die Deutsche Python Mailingliste <python-de.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-de>, <mailto:python-de-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-de/>
List-Post <mailto:python-de@python.org>
List-Help <mailto:python-de-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-de>, <mailto:python-de-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <0c0ce991-1e48-dd0e-9959-0ec3b22b4e0e@mail.de>
X-Mailman-Original-References <Python-20170108184230@ram.dialup.fu-berlin.de> <3dee2ce4-274a-3b59-756c-3559e7c568c1@mail.de> <mailman.382.1483969007.2395.python-de@python.org> <edhsa2F4aukU1@mid.individual.net> <cc585ec8-d4b4-685b-0a1d-ef62327c0e96@mail.de> <mailman.401.1483983912.2395.python-de@python.org> <edi2t2F5vcjU1@mid.individual.net> <6c4f418c-b74a-9968-82e9-a4eb45ca1237@mail.de> <mailman.405.1483988893.2395.python-de@python.org> <edi8c5F7b3eU1@mid.individual.net>
Xref csiph.com de.comp.lang.python:4645

Show key headers only | View raw


On 09.01.2017 20:59, Hermann Riemann wrote:
> Wie soll ich das etwa bei
>
> if not os.access(ordnername, os.F_OK):
>    os.makedirs(ordnername)
>
> machen?
>

Zum Beispiel folgendes verwenden:

os.makedirs(ordnername, /exist_ok=True/)


>
>> - mehr Variablen für Zwischenergebnisse
>
> Wo dann die Namen zu Verwirrung führen können.
> i52, i53 i54 ..
>

Richtig. Deswegen sprechende Namen. :)

>> - die richtigen Python-Idiome anwenden
>
> Das sehe ich pragmatisch, aber nicht stur.
> Die Suche nach Python-Idiome hat mich zu nützlichen Tipps geführt,
> weil etliches in den Bücher, an die ich mich orientiere,
> nicht enthalten ist.

Finde ich gut!

>
>> - Default-Objekte anstelle von None verwenden
>
> Extra Objekte erzeugen?

Ich geb mal ein Beispiel. Folgende Ausgangssituation:

def xxx(input):
     if input:
         liste = input.split()
         for item in liste[:-1]:
             print(item, end='')
             print('#####', end='')
         if len(liste) >= 1:
             print(liste[-1])


erster Schritt (Reduktion der Einrückung):

def xxx(input):
     input = input or '' # Default-Objekt:''
     liste = input.split()
     for item in liste[:-1]:
         print(item)
         print('#####')
     if len(liste) >= 1:
         print(liste[-1])


zweiter Schritt (Idiom erkennen):

def xxx(input):
     input = input or ''
     liste = input.split()
     print('#####'.join(liste))


Ich gebe zu, das Beispiel ist ein wenig konstruiert, aber es gibt oft 
einen Weg, kürzer und einfacher zu schreiben. :)


Sven

Back to de.comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: [Python-de] Wie sieht Python fuer mich aus? "Sven R. Kunze" <srkunze@mail.de> - 2017-01-09 14:31 +0100
  Re: [Python-de] Wie sieht Python fuer mich aus? Hermann Riemann <nospam.gerct08@hermann-riemann.de> - 2017-01-09 17:33 +0100
    Re: [Python-de] Wie sieht Python fuer mich aus? "Sven R. Kunze" <srkunze@mail.de> - 2017-01-09 18:45 +0100
      Re: [Python-de] Wie sieht Python fuer mich aus? Hermann Riemann <nospam.gerct08@hermann-riemann.de> - 2017-01-09 19:25 +0100
        Re: [Python-de] Wie sieht Python fuer mich aus? "Sven R. Kunze" <srkunze@mail.de> - 2017-01-09 20:08 +0100
          Re: [Python-de] Wie sieht Python fuer mich aus? Hermann Riemann <nospam.gerct08@hermann-riemann.de> - 2017-01-09 20:59 +0100
            Re: [Python-de] Wie sieht Python fuer mich aus? "Sven R. Kunze" <srkunze@mail.de> - 2017-01-09 21:44 +0100
      Re: [Python-de] Wie sieht Python fuer mich aus? Hermann Riemann <nospam.gerct08@hermann-riemann.de> - 2017-01-09 19:37 +0100
    Re: [Python-de] Wie sieht Python fuer mich aus? Thomas Orgelmacher <trash@odbs.org> - 2017-01-09 18:41 +0100
      Re: [Python-de] Wie sieht Python fuer mich aus? Hermann Riemann <nospam.gerct08@hermann-riemann.de> - 2017-01-09 19:11 +0100
        Re: [Python-de] Wie sieht Python fuer mich aus? Thomas Orgelmacher <trash@odbs.org> - 2017-01-09 19:56 +0100
    Re: [Python-de] Wie sieht Python fuer mich aus? Hans-Peter Jansen <hpj@urpla.net> - 2017-01-09 19:51 +0100
      Re: [Python-de] Wie sieht Python fuer mich aus? Hermann Riemann <nospam.gerct08@hermann-riemann.de> - 2017-01-09 20:19 +0100
    Re: [Python-de] Wie sieht Python fuer mich aus? Stefan Schwarzer <sschwarzer@sschwarzer.net> - 2017-01-13 08:40 +0100

csiph-web