Search Results

Search found 200 results on 8 pages for 'pythonic'.

Page 5/8 | < Previous Page | 1 2 3 4 5 6 7 8  | Next Page >

  • What should a Python developer know while learning Ruby?

    - by C J
    I have been a Python programmer for about 18 months, consisting of one internship and a few side projects, and I consider myself pretty comfortable in the language. However, there seems to be a lot of attention on Ruby in the programming field, but not a lot on Python anymore. So in learning Ruby, are there going to be Pythonic things that are just bad practices in Ruby? What should I watch out for, and what should I avoid?

    Read the article

  • Using dot To Access Object Attribute and Proper abstraction

    - by cobie
    I have been programming in python and java for quite a number of years and one thing i find myself doing is using the setters and getters from java in python but a number of blogs seem to think using the dot notation for access is the pythonic way. What I would like to know is if using dot to access methods does not violate abstraction principle. If for example I implement an attribute as a single object and use dot notation to access, if I wanted to change the code later so that the attribute is represented by a list of objects, that would require quite some heavy lifting which violates abstraction principle.

    Read the article

  • PyQt design issues

    - by Falmarri
    I've been working on a my first real project using PyQt lately. I've done just a little bit of work in Qt for C++ but nothing more than just messing around. I've found that the Qt python bindings are essentially just a straight port of C++ classes into python, which makes sense. The issue is that this creates a lot of messy, unpythonic code. For example if you look at QAbstractItemModel, there's a lot of hoops you have to go through that forces you to hide the actual python. I was just wondering if there's any intention of writing a python implementation of Qt that isn't necessarily just a wrapper? Either by Nokia or anyone else? I really like Qt but I would love to be able to write more pythonic code. I hope this is OK to ask here. I'm not trying to start a GUI war or anything.

    Read the article

  • What is a *slightly* less extreme equivalent to being "fluent" in a language?

    - by Mehrdad
    tl;dr: What is a less extreme (but still noticeable) alternative to the word "fluent", when saying e.g. "I am fluent in C++/Python/whatever?" I think I can call myself "fluent" in C#, because I know the language and runtime very well, and I'm very familiar with the .NET framework's APIs and classes, etc. I would like to claim the same thing for Python and C++. But while I can program in Python (I did so for an entire summer, making a website with Django), for example, I would not call myself fluent because my code isn't always "Pythonic" (e.g. using map/filter vs. list comprehensions), and I'm not too intimate with some aspects of the language and standard library yet (e.g. the introspection API, etc.). Is there a word or phrase I can use on e.g. a resume to describe what I know? I can think of "very familiar with", but is there a better word/phrase I can use?

    Read the article

  • Python readability hints for a Java programmer

    - by Samuel Carrijo
    I'm a java programmer, but now entering the "realm of python" for some stuff for which Python works better. I'm quite sure a good portion of my code would look weird for a Python programmer (e.g. using parenthesis on every if). I know each language has its own conventions and set of "habits". So, from a readability standpoint what are conventions and practices which is "the way to go" in Java, but are not really the "pythonic way" to do stuff?

    Read the article

  • More efficient programming than Web.py?

    - by Luke Stanley
    I love webpy, it's really quite Pythonic but I don't like having to add the url mappings and create a class, typically with just 1 function inside it. I'm interested in minimising code typing and prototyping fast. Does anyone have any up and coming suggestions such as Bobo, Bottle, Denied, cherrypy for a lover of webpy's good things? What makes it a good reason? Also I don't mind missing out (strongly) text based templating systems, I use object oriented HTML generation.

    Read the article

  • How to use Python list comprehension (or such) for retrieving rows when using MySQLdb?

    - by Erik Nygren
    Hey all, I use MySQLdb a lot when dealing with my webserver. I often find myself repeating the lines: row = cursor.fetchone() while row: do_processing(row) row = cursor.fetchone() Somehow this strikes me as somewhat un-pythonic. Is there a better, one-line way to accomplish the same thing, along the lines of inline assignment in C: while (row = do_fetch()) { do_processing(row); } I've tried figuring out the syntax using list comprehensions, but I can't seem to figure it out. Any recommendations? Thanks, Erik

    Read the article

  • Python XML + Java XML interoperability.

    - by erb
    Hello. I need a recommendation for a pythonic library that can marshall python objects to XML(let it be a file). I need to be able read that XML later on with Java (JAXB) and unmarshall it. I know JAXB has some issues that makes it not play nice with .NET XML libraries so a recommendation on something that actually works would be great.

    Read the article

  • Can I filter a django model with a python list?

    - by Rhubarb
    Say I have a model object 'Person' defined, which has a field called 'Name'. And I have a list of people: l = ['Bob','Dave','Jane'] I would like to return a list of all Person records where the first name is not in the list of names defined in l. What is the most pythonic way of doing this?

    Read the article

  • How to handle the pylint message: Warning: Method could be a function

    - by biffabacon
    Being new to Python, I decided to get some feedback on a class I'd written ASAP so I ran it against pylint. Is the message it gave "Warning: Method could be a function" telling me that it would be better to move this method out of the class because it doesn't use any instance variables? In c# I would make this a static method. What's the most pythonic thing to do here?

    Read the article

  • Python re.IGNORECASE being dynamic

    - by Adam Nelson
    I'd like to do something like this: re.findall(r"(?:(?:\A|\W)" + 'Hello' + r"(?:\Z|\W))", 'hello world',re.I) And have re.I be dynamic, so I can do case-sensitive or insensitive comparisons on the fly. This works but is undocumented: re.findall(r"(?:(?:\A|\W)" + 'Hello' + r"(?:\Z|\W))", 'hello world',1) To set it to sensitive. Is there a Pythonic way to do this? My best thought so far is: if case_sensitive: regex_senstive = 1 else: regex_sensitive = re.I re.findall(r"(?:(?:\A|\W)" + 'Hello' + r"(?:\Z|\W))", 'hello world',regex_sensitive)

    Read the article

  • Nested generator functions in python

    - by Yuval A
    Consider a tuple v = (a,b,c) and a generator function generate(x) which receives an item from the tuple and generates several options for each item. What is the pythonic way of generating a set of all the possible combinations of the result of generate(x) on each item in the tuple? I could do this: v = (a,b,c) for d in generate(v[0]): for e in generate(v[1]): for f in generate(v[2]): print d,e,f but that's just ugly, plus I need a generic solution.

    Read the article

  • Is frozenset adequate for caching of symmetric input data in a python dict?

    - by Debilski
    The title more or less says it all: I have a function which takes symmetric input in two arguments, e.g. something like def f(a1, a2): return heavy_stuff(abs(a1 - a2)) Now, I want to introduce some caching method. Would it be correct / pythonic / reasonably efficient to do something like this: cache = {} def g(a1, a2): return cache.setdefault(frozenset((tuple(a1), tuple(a2))), f(a1, a2)) Or would there be some better way?

    Read the article

  • Python: import the containing package

    - by guy
    In a module residing inside a package, i have the need to use a function defined within the __init__.py of that package. how can i import the package within the module that resides within the package, so i can use that function? Importing __init__ inside the module will not import the package, but instead a module named __init__, leading to two copies of things with different names... Is there a pythonic way to do this?

    Read the article

  • Python loop | "do-while" over a tree

    - by johannix
    Is there a more Pythonic way to put this loop together?: while True: children = tree.getChildren() if not children: break tree = children[0] UPDATE: I think this syntax is probably what I'm going to go with: while tree.getChildren(): tree = tree.getChildren()[0]

    Read the article

  • How should I write this string-prefix check so that it's idiomatic Python?

    - by Kevin Stargel
    I have a couple of lists of items: specials = ['apple', 'banana', 'cherry', ...] smoothies = ['banana-apple', 'mocha mango', ...] I want to make a new list, special_smoothies, consisting of elements in smoothies that start with the elements in specials. However, if specials is blank, special_smoothies should be identical to smoothies. What's the most Pythonic way to do this? Is there a way to do this without a separate conditional check on whether specials is blank?

    Read the article

  • Calling methods in super class constructor of subclass constructor?

    - by deamon
    Calling methods in super class constructor of subclass constructor? Passing configuration to the __init__ method which calls register implicitely: class Base: def __init__(self, *verbs=("get", "post")): self._register(verbs) def _register(self, *verbs): pass class Sub(Base): def __init__(self): super().__init__("get", "post", "put") Or calling register explicitely in the subclass' __init__ method: class Base: def __init__(self): self._register("get", "post") def _register(self, *verbs): pass class Sub(Base): def __init__(self): _register("get", "post", "put") What is better or more pythonic? Or is it only a matter of taste?

    Read the article

  • Why would it be necessary to subclass from object in Python?

    - by rmh
    I've been using Python for quite a while now, and I'm still unsure as to why you would subclass from object. What is the difference between this: class MyClass(): pass And this: class MyClass(object): pass As far as I understand, object is the base class for all classes and the subclassing is implied. Do you get anything from explicitly subclassing from it? What is the most "Pythonic" thing to do?

    Read the article

  • Why can I not access this class member in python?

    - by Peter Smit
    I have the following code class Transcription(object): WORD = 0 PHONE = 1 STATE = 2 def __init__(self): self.transcriptions = [] def align_transcription(self,model,target=Transcription.PHONE): pass The important part here is that I would like to have a class member as default value for a variable. This however gives the following error: NameError: name 'Transcription' is not defined Why is this not possible and what is the right (pythonic) way to do something like this.

    Read the article

  • Python/Django Concatenate a string depending on whether that string exists

    - by Douglas Meehan
    I'm creating a property on a Django model called "address". I want address to consist of the concatenation of a number of fields I have on my model. The problem is that not all instances of this model will have values for all of these fields. So, I want to concatenate only those fields that have values. What is the best/most Pythonic way to do this? Here are the relevant fields from the model: house = models.IntegerField('House Number', null=True, blank=True) suf = models.CharField('House Number Suffix', max_length=1, null=True, blank=True) unit = models.CharField('Address Unit', max_length=7, null=True, blank=True) stex = models.IntegerField('Address Extention', null=True, blank=True) stdir = models.CharField('Street Direction', max_length=254, null=True, blank=True) stnam = models.CharField('Street Name', max_length=30, null=True, blank=True) stdes = models.CharField('Street Designation', max_length=3, null=True, blank=True) stdessuf = models.CharField('Street Designation Suffix',max_length=1, null=True, blank=True) I could just do something like this: def _get_address(self): return "%s %s %s %s %s %s %s %s" % (self.house, self.suf, self.unit, self.stex, self.stdir, self.stname, self.stdes, self.stdessuf) but then there would be extra blank spaces in the result. I could do a series of if statements and concatenate within each, but that seems ugly. What's the best way to handle this situation? Thanks.

    Read the article

  • Python: Comparing specific columns in two csv files

    - by coder999
    Say that I have two CSV files (file1 and file2) with contents as shown below: file1: fred,43,Male,"23,45",blue,"1, bedrock avenue" file2: fred,39,Male,"23,45",blue,"1, bedrock avenue" I would like to compare these two CSV records to see if columns 0,2,3,4, and 5 are the same. I don't care about column 1. What's the most pythonic way of doing this? EDIT: Some example code would be appreciated.

    Read the article

  • is there a better way of replacing duplicates in a list (python)

    - by myeu2
    Given a list: l1: ['a', 'b', 'c', 'a', 'a', 'b'] output: ['a', 'b', 'c', 'a'_1, 'a'_2, 'b'_1 ] I created the following code to get the output. Its messyyy.. for index in range(len(l1)): counter = 1 list_of_duplicates_for_item = [dup_index for dup_index, item in enumerate(l1) if item == l1[index] and l1.count(l1[index]) > 1] for dup_index in list_of_duplicates_for_item[1:]: l1[dup_index] = l1[dup_index] + '_' + str(counter) counter = counter + 1 Is there a more pythonic way of doing this? I couldnt find anything on the web.

    Read the article

  • Is there a better way to write this URL Manipulation in Python?

    - by dnolen
    I'm curious if there's a simpler way to remove a particular parameter from a url. What I came up with is the following. This seems a bit verbose. Libraries to use or a more pythonic version appreciated. parsed = urlparse(url) if parsed.query != "": params = dict([s.split("=") for s in parsed.query.split("&")]) if params.get("page"): del params["page"] url = urlunparse((parsed.scheme, None, parsed.path, None, urlencode(params.items()), parsed.fragment,)) parsed = urlparse(url)

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8  | Next Page >