New answers tagged

-2

I don't know if it's bad form to answer this here but I'm going to provide a few pointers anyway. There is a definite bug in the first if statement of the user function. You are using a lot of global variables. Usually considered a "code smell" to experienced programmers, it seems an obvious thing to do for beginners. You cannot modify a global variable ...


0

Perhaps learn how to use html + bootstrap. Bootstrap is a modern package to make responsive sites where the CSS and JavaScripts are almost, if not all, taken cared of for you. So no need to dig way to deep in html+css+js. What you will do after you know enough of bootstrap is to go over to these bootstrap examples then start your web designs from there. ...


0

I almost never use the collection literals for empty collections in my Python code and prefer the named list, set, dict and tuple constructors instead. The reason for this is that the literals can be quite confusing. For example, {} is not the empty set but an empty dictionary which is contrary to what anybody with a background in mathematics would ...


2

The difference between my_list = list() and my_list = [] is that list requires a namespace lookup, first in the module level globals, then in the builtins. On the other hand, [] is a list literal and is parsed as creating a new list from the language, which doesn't require any name lookups. So the literal is faster on object creation. Otherwise, ...


-1

Other than the fact that it allows multiple superclasses, Python's inheritance is not substantially different to Java's, i.e. members of a subclass are also members of each of their supertypes[1]. The fact that Python uses duck-typing makes no difference either: your subclass has all of the members of its superclasses, so is able to be used by any code that ...


0

The LGPL grants you distribution rights with certain conditions. If you aren't distributing the library yourself then there's nothing you need to do. You simply need to document that your program requires a separate blah library in order to work, and that any implementation of a blah library compatible with <the library you think works best>. Nowhere ...


1

What a build system like Bazel might give you? Self-contained builds with all dependencies, including all binary extensions dependencies, put into one package (see py_binary). This additionally helps keep as few things installed on a prod machine as possible. limiting the attack surface. Easily invoked unit tests in different environments. Compiling and ...


3

Instead of thinking about the potential benefits of a potential tool, think about the actual issues and bottlenecks you encounter in your workflow—only then you should focus on the tools which actually solve those issues. For instance, you may have a slow feedback cycle between developers and QA. Imagine a developer commits the changes on Monday at 5 p.m.; ...


1

If you import the entries one by one, then you should be able to know when the import was terminated simply by looking at the destination database (I imagine that there is some unique identifier in the destination database which makes it possible for you to link every product there to a product in the source database, right?) If you do a bulk insert, you ...


0

There's no easy way to get the info from .startswith, but you can construct a regular expression that gives you that info. An example: import re prefixes = ("foo", "moo!") # Add a ^ before each prefix to force a match at the beginning of a string; # escape() to allow regex-reserved characters like "*" be used in prefixes. regex_text = "(" + "|".join("^" ...


0

First ditch the cron job. Convert the program so it has a long running loop. You don't need 60 emails an hour to tell you it's broken. To scale, compute a stable hash of the username (or any other stable attribute) of the user. Decide how many copies of the bot to run (you can change your mind about how many). We'll call this number N. Take the hash ...


2

Is using __import__('module_name') an antipattern in Python? The api for __import__ is somewhat misleading. I personally would prefer to avoid it where possible. The docs for Python 3 state: Direct use of __import__() is also discouraged in favor of importlib.import_module(). Here's the API for __import__: mod = __import__( module, # string ...


0

You can use the platform library to run different commands based on which OS flavor and/or version it's running under.


0

Consider object oriented programming. If you have procedures that need to act on this data, a class groups them together nicely. Your function, that takes the raw messages, could be used to construct these objects. For maintainability try a tell, don't ask approach. You should endeavor to tell objects what you want them to do; do not ask them ...


0

I've had a similar, but simpler, situation with a C program running on different linux distros, and using maybe half a dozen command-line tools. What I did was write C functions char *whichpath(char *command), and similarly for locatepath(). The which version just does popen("which command","r") and reads the pipe, simply letting which find the (path to the) ...


-1

Talking about strict liability regarding licensing, the safest option would likely be the MIT license: The MIT License (MIT) Copyright (c) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including ...


7

If you add variables to self in the constructor of Class and don't call Class.__init__() in the constructor of Subclass, then these variables will not be in your Subclass object. See that question for an example. In your case, Class is simply a function repository. So, it will not make a difference. However, in the future, you may need to add some ...


1

I came across this question looking for a similar answer myself. What I have found is the "Rete Algorithm", which is well explained here: https://techondec.wordpress.com/2011/03/14/rete-algorithm-demystified-part-2/ For your example, country would then be an Alpha node, below which each country(-group) hangs, and onto which you connect the actions, which ...


2

Not much of coding in Python and its long time since I coded in C. For C programs, I used to prefer top-down, because that is how I design my programs. If a calls b, b is listed after a. I also used to have a header for each .c file that lists all functions in it and included in the .c file. I follow the same model in Java class methods now.


-2

The point of writing a method is to do one thing in an obviously correct way. This principle is usually applied to explain why over-long methods are bad; a method should fit on your monitor in one piece. But it also cuts the other way: a method should not be so small that several fit on your monitor at the same time! This means that it is quite irrelevant ...


0

To do an estimate, your sample should be randomized. Don't just look at the first 100 lines. We have random access to these files. Use it. Those first lines might be radically different than the rest. It's ok to dive into a random spot, scan for a line terminator, count until you get to the next one, repeat. Don't bother to exclude lines that have been ...


-1

A very basic way to parse this string might be thestring ='\ #: somethings\nchars0 "substr0"\nchars1 "substr1"\n\n\ #: something\nchars0 "substr2"\nchars1 "substr3"' for token in thestring.split('\n'): if "#" in token: handler.heading(token) elif "" == token: handler.section(token) else: handler.body(token) print ...


3

Many security "holes" are the result of programming mistakes. Programmers necessarily make assumptions about how their programs will be used and sometimes these assumptions are incorrect. A good example is Bobby Tables. At one time it was considered a common practice to accept input from a user, concatenate that with commands to a database, then execute ...


1

Wappalyser will not be able to see the backend code running on a remote server. If you are running your Django site locally, then it will be able to inspect and report on everything. or to put it another way, you do not have access to Youtube's backend server so you cannot tell anything about it or the technology it uses. You do have full access to your ...



Top 50 recent answers are included