Are there anyone from aussie here? The ANZ sent me some message on stackoverflow, and they said there are a job can be offer, but I have been back china? anyone like to join this company?
@smci I don't want to look at your solution because I've been vaguely thinking about it myself. But here's something that might help to reduce the number of cases. In the formula for a primitive Pythagorean triad, exactly one of m or n must be even. If they're both odd (or even), then all sides are even, and hence the triad's not primitive. There's a cute reduction to a primitive triad if m & n are both odd. Let m'=(m+n)/2, n'=(m-n)/2.
@JonClements It depends on whether that particular 2nd-degree connection of yours has 'Show connections' turned on or not. (Many people disabled it after the massive LinkedIn connections-harvesting hack by spammers around 2013-4, when LinkedIn got in huge trouble). So if your 2nd-degree connection has it disabled, you just have to start browsing/guessing which 1st-degree connection of yours is the common connection (e.g. previous employers, colleges, location). Or ask either of them.
if I have dict "a" and "b" I want to create a list which is a + b. I want to check if a key exists in b. I know this can be done with a simple if in condition. But I need to check in a list comprehension.
For example I have three dicts and an empty list h = {"a":"1"} l = {"b":"1"} m = {"c":"1"} b = [] I'm trying to create a list of dictionaries so I used the below code and it works b
b.append(dict(h,**l,**{"d":"1"}))
But now I need to check if a key exists before appending the dict I tried the below code and it throws a syntax error
b.append(dict(h,**l,**{"d":"1"}, **(m if "c" in m.keys()))
h = {"a":1}
l = {"b":3, "e":4}
m = {"c":2}
from collections import Counter as Ctr
Ctr(h) + Ctr(l) + Ctr(m)
Counter({'e': 4, 'b': 3, 'c': 2, 'a': 1})
That easy! I mean yes you could use a dict comprehension, but why go to more work? Counter was born for this.
@PM2Ring Yes perhaps, my proof is too long, it needs aggressive pruning. Anyway do see if you can come up with your own solution, if you get stuck, peek at the existing ones.
@Stramzik: note for Counter, the keys can be anything (strings, ints, objects, anything hashable), but the values must be integers, not strings. There is no reason for the values to be string in your code. (If it was imported from JSON, then just convert them to int when you import them)
@Stramzik only considers one key value pair That doesn't tell us how you want dupes to be handled. Do you want to ignore dupe keys, or should a dupe replace the existing value with the new one?
I know I have been suggested to use django BaseModel but the problem will still persist because it's related to classmethods not reventing the wheel or anythiing like that. Classmethods will be needed to be put in the Basemodel of django too.
@Stramzik Ok. But you can't use the dict(**h, **m) constructor, since (as you've discovered) need to be unique. But you can use the dict.update method.
class BrokenMeta(type):
def __init__(cls, foo, bar):
pass
class Broken(metaclass=BrokenMeta):
pass
# TypeError: __init__() takes 3 positional arguments but 4 were given
Then yes, exec is the solution to the problem as you stated it. But your real problem is actually that you have code in a string. Is there a good reason for that?
@whatsnext you should to exec it with a custom globals dictionary. The dictionary contains the ABC class afterwards. Unless you want all names, then a pure exec at your own global scope should be fine.
@Stramzik Dude, if the example data you posted wasn't representative of the task, we don't have a crystal ball to figure it out what your data might look like and how to handle it. Always good to provide an MCVE. (You showed an example with strings of integers. Then you said "and different values not just 1." But nowhere does that say "values can be arbitrary Python object, not just strings or integers". Example would have been good. To avoid wasting the time of people trying to help you.)
@VisheshMangla In the context of the cPython executable, 'compile' can only mean 'compile Python source into Python bytecode'. (whereas Cython is another thing, as you point out). See Ned Batchelder: Is Python interpreted or compiled? Yes." (Obviously other languages will do things differently, as MM said).
@VisheshMangla "Please read from bottom and then go to the top" is an indication that you aren't thinking about your readers. Why not just put the text at the top of your paste?
Similarly, "I 'm getting modelbase with self.model.__class__.__name__ which I expect will give me the class name as string" night easily be thrown around in a Django conversation, but means little when dropped without context into a chat.
@VisheshMangla Not quite. It is unclear where you want to get the name. At global scope? Inside foo? When inside foo, the name of ABCD or the name self's class?
With real respect for your wish to be understood, I point this out because such behaviour, repeated endlessly, is rather demotivating to those who genuinely want to help.
@MisterMiyagi Installing of jupyter aborted throwing following error
"Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/3.7' Consider using the `--user` option or check the permissions."
@YatShan More than optimistic to expect to be able to import a module whose installation failed. Perhaps it would ave been better to mention that first.
I presume you are a mac user who accepted the change to zsh? I'm still using bash.
Could be that zsh doesn't pick up changes in the $PATH directory contents (pip installs scripts for its entry points in the venv's /bin directory. jupyter is, IIRC, such a script).
Fair enough. Normally when I install a module with pip the new binaries are picked up immediately by my shell. I'd be interested to know if that were a bash/zsh difference, but only out of idle curiosity.
Using zsh locally is okay for me because there I use the shell at most for 1-liners. Booting a fresh shell after making env changes is a habit, so frankly I've never noticed that zsh might be lazy with $PATH changes.
a pip install with a console_script makes it immediately available in my current zsh session.
Hi guys, I am trying to make my own dns server, and I found many good tutorials, but one thing bothers me in all of them. Namely I have to set the ip of my own dns server in all the clients. In linux for example under /etc/resolvconf.conf show here: superuser.com/questions/1093419/… But how do I get my own dns server to be used automatically?
Like when I plug my pc to my router and have dhcp and dns configured to auto I just use the router as a dns, how can I achieve that when I configure clients to use dns auto it uses my dns server, instead of the router or isp one?
DHCP clients should treat the DHCP server as authoritative for DNS service information. You would therefore need to reconfigure your DHCP server to serve out the address of your DNS server. Otherwise, just add its IP address to the settings in your IP interface(s) manually.
But make sure there's also some other DNS source in there (8.8.8.8 or 8.8.4.4 from Google would be a good choice).
I see, so either I run dhcp and dns together to have clients autodetect both or I configure my dhcp server to tell clients where my dns server is. I just hope my router has that functionality
Do you by chance know how that settings is called in consumer routers? Or under what rubric it is to find?
While you've been having this dialogue with others, I've been untangling a completely broken config system for my library, and I've not had the code run correctly once in the last 3 hours. I'm not suggesting that you don't ask for help, but please keep in mind the frequency at which you're asking.
@VisheshMangla Whether a code throws a SyntaxError or not is not something you should need an expert for. A regular IDE or linter, or even just importing the code in the interpreter, tells you that.
@VisheshMangla I'm talking about a single feature of an app that I've been working on for some 4 months now, not that I haven't been having issues for the full 4 months
With real respect for your wish to be understood, I point this out because such behaviour, repeated endlessly, is rather demotivating to those who genuinely want to help.
The point is that you're asking too many questions, especially ones that you should be able to solve yourself. If you continually give us the impression that solving a problem for you will only lead to you asking about a new problem 5 minutes later, then we will stop wasting our time on your problems.
You might consider writing individual components and testing them before attempting to fit them together with glue logic. Do you do any testing? (Other than banging away at a keyboard).
@VisheshMangla Ok, but the pattern here is that you're implementing something you think should work, it doesn't work, and then you bring it here to be fixed within very little time between events. If you were spending 3 hours on the issue, we couldn't possibly be getting such a scatter-gun of blocks of different code. I'm suggesting that you spend more time researching around the problem before asking, please.
@holdenweb Do you know, is this common in routers nowadays or quite rare? I can't seem to find it in mine, but I found that the linksys LRT2x4 has DNS Local Database feature of LRT2x4. So I wonder how to find out if my router can do that? Is there a keyword to search for like router model set dns server manually or something like that?
For example, I'm currently writing an API endpoint that archives the events related to a given licence. These are my tests: 1) With no events, no archive is created; 2) Verify file and event counts for five different counts; 3) verify that a non-archivable event raises an exception; 4) verify a 404 response when an invalid license id is used.
TBH I haven't read any, because I haven't seen any intelligent discussion about the content. Just "what's wrong with this, please"? You've already given the answer: the answer is, it's horrible code. That's ok, we all write horrible code when we start. But most of us do our bleeding in private ;-).
My own Django code is currently pretty horrible, and I've removed three silly bugs already. Treat the error as a clue, and undertake a detective mission to solve the real problem: you don't understand why your code is doing what it's doing.
Or start the other way around. Start from a template mostly from the docs, which you now is working. Run that, it works. Keep adding small increments, it still works. At one point it breaks, bam you know where you added something that broke it
Google isn't a pair of programming legs, it's a crutch. If you want to program with a trowel by throwing bits of code together you've found on Google then you are wasting your own time and everybody's here. If you don't want to learn to program, I'd suggest you go ask somewhere else.
You can't just "dabble" with complex things like Django. You need to commit to a real effort of understanding, or pay someone who already has the necessary knowledge.
@VisheshMangla No, holdenweb was just putting in better terms what I said earlier. You have no idea how many errors we're facing (bleeding wounds) because we're not posting them in here all the time (hence, we're bleeding in private)
Idiom? No, just a metaphor I invented to describe the cruelty of realising that your code doesn't do what you think it should because you put dumb mistakes in it. Still a daily experience for every practising programmer.
:-). Lordy, hallelujah, the test just agreed that it creates precisely one file with $ARCHIVE_BATCH_SIZE events on the license! On to the third test ...
Ha, forgot I'd found this letter from Richard Feynman yesterday. That explains my nightmare last night about being back at uni and meeting my old advisor
@VisheshMangla I came back to the transcript being full of your confusing questions still, with no real outcome other than wasting the time and patience of the regulars here. So let me officially escalate your level to "risk of being a help vampire". Read the linked guide, and change how you ask here, because very soon you will not be able to ask here at all. And for reference:
Imagine that you won a competition, and the prize is a free session with a Python think-tank who normally charge $1000 per hour. Don't waste that prize!
anybody able to advise me on how to get question permissions back? I have edited all questions and have no idea why it isn't auto activating or what to do to get it to allow me again
deleted questions count towards the block... so you might want to consider it or hope that any edits you've made to the visible stuff will get noted and you might get an upvote on etc...
@VisheshMangla No. You have depleted your trial-and-error options. You will actually have to step back and spend a lot more time thinking about what to ask and how. If you don't have a proper, informative MCVE you're doing it wrong. If you say "sorry there was a typo" you're doing it wrong. If you say "google gives nonsense results" you're doing it wrong. You seem to be missing the basics of python, so learn it first. Finnish a good tutorial. This room is not a replacement for that.
@Kwsswart A couple of your Q's I thought you put some effort into even if they were a little long - you should probably look at how to do a mcve - so I've given an upvote/two... if someone else notices your posts and you can an upvote it might be enough to push you over the Q block stuff...
hey I have a project which I run in pycharm, If I want to run it on another IDLE I get an Module not found error, is pycharm something doing that Im not aware off ?
@William you need to append the path of the python's script folder to you environment path varible in order to run that version of python w/o any virtual env
If I read a file timestamp (creation time, modification time, etc) from two different operating systems, can I safely compare them with ==? Will they definitely be exactly the same? They will, right?
Ok, good. I was planning to identify files based on their device and inode at first, but then I learned that the device id isn't consistent across reboots
/me sniffs pasty... and eyes roganjosh... this better not be one of those vegan ones as I hear you don't like that place you mentioned earlier... they're not great but always appreciated!
that above transcript is why when my wife asked me "if they don't pick you up for teaching a course this fall: why don't you do codementor instead?" - I gave her a look of horror
@roganjosh Sure... I can offer you better than an insurance policy... just keep me fed regularly with Greggs' proper sausage rolls and then you won't even need an insurance policy! :)
@LinkBerest I haven't looked recently but think he did use to do a fair bit but was something like $70+/15 mins or something :p
yeah, occasionally I point a graduate level student to it for extra practice/money and they are the $15 ones (also perfectly fine for helping an UG student with a homework problem)
^ all of them reported to me that their mentees were shocked they wouldn't just give them the answer or do their homework for them
@VisheshMangla you were kicked because following the warning I gave you not long ago, asking about an error and responding "I can't [give you code]" is unacceptable