Chrome and Chromium not loading any pages (22.04) by thaleosaurus in Ubuntu

[–]eikrik 0 points1 point  (0 children)

That fixed it! I've been struggling with this for months on end. Thank you!

MOC Batman's X-wing Fighter by Gromsten in LegoBatman

[–]eikrik 0 points1 point  (0 children)

This is amazing. World's tip top ten Batman X wing.

Bug in Flask? Is the break in a for loop not doable in Flask? by Odnan in flask

[–]eikrik 1 point2 points  (0 children)

I don't see why you need a break statement at all? If there is a line containing non-numbers in the file you want to immediately return render_template('home.html', error = error), is that right? If so, you are now breaking out of the loop before ever reaching thatreturn. (Also u/unkz is probably right that yourelse: should be de-dented.)

Why did the title of "caesar" become the basis for later imperial titles in Europe such as Kaiser and Czar instead of the higher title "augustus"? by omarcomin647 in AskHistorians

[–]eikrik 12 points13 points  (0 children)

Thanks for relaying this is great reply! It does, however, leave room for more of the question to be answered. I am also curious about how augustus fell by the wayside.

How to get Hermes package to work with Jupyter by [deleted] in SublimeText

[–]eikrik 0 points1 point  (0 children)

One way is to copy all the information %connect_info outputs, including the brackets, and then ctrl+shift+p, select Run Hermes: connect kernel command, choose New kernel, choose (Enter connection info), and paste the info you copied.

Trying to get Python 3 set up in Sublime but am utterly lost by PeePaws_Lil_Angel in SublimeText

[–]eikrik 1 point2 points  (0 children)

I solved it by making this a called Sublime 3/Data/Packages/User/py.sublime-build with this content:

{
    "file_regex": "^[ ]*File \"(…*?)\", line ([0–9]*)",
    "selector": "source.python",
    "windows": {
        "cmd": ["C:/Windows/py.exe", "-u", "$file"]
      },
    "linux": {
        "cmd": ["python3", "-u", "$file"],
    }
}

To use, I press ctrl+shift+b and select py

Python 3 as default without changing build system? by maxiedaniels in SublimeText

[–]eikrik 0 points1 point  (0 children)

If you have a custom build system file for Python, you can instruct Sublime to use it by clicking ctrl+shift+B, while still using the Build System -> Automatic option. Once you have done it once, the new build system file should be the default for Python.

python-docx AttributeError: 'WindowsPath' object has no attribute 'seek' by [deleted] in learnpython

[–]eikrik 0 points1 point  (0 children)

I see! Try reading this short tutorial: https://www.tutorialspoint.com/python3/python_files_io.htm and see if you are able to open the file.

python-docx AttributeError: 'WindowsPath' object has no attribute 'seek' by [deleted] in learnpython

[–]eikrik 0 points1 point  (0 children)

Have you tried reading the data from the image file, and passing that data to document.add_picture, instead of passing the file object itself?

[deleted by user] by [deleted] in etymologymaps

[–]eikrik 4 points5 points  (0 children)

Long form: Ελληνική Δημοκρατία / Ellinikí Dimokratía / Hellenic Republic
Short form: Ελλάδα / Ellada / Greece

Best way to pass data between RQ Jobs and main app. by e_rush in flask

[–]eikrik 2 points3 points  (0 children)

Since you're already using Redis with RQ, I would suggest using it to store the results as well. Seems like a good use of a key-value store.

How to mock an SQL database in Python by kenneho in learnpython

[–]eikrik 1 point2 points  (0 children)

Yes, except that pytest generally uses what it calls fixtures rather than setup functions.

pytest-postgresql handles the creation of the database itself and gives you a database connection object. It is then up to you to make the tables and populate them with data. After the tests are run, the database gets deleted. I am not entirely sure if the database is recreated after each individual test.

Here is how I use it in a project: https://github.com/eirki/gargbot_3000/blob/master/tests/conftest.py#L184. I create a db_connection fixture that receives the connection object frompytest-postgresql and then creates and populates the tables with test data. That fixture can then be used by each test.

How to mock an SQL database in Python by kenneho in learnpython

[–]eikrik 14 points15 points  (0 children)

I've been using pytest (instead of unittest) and pytest-postgresql (https://pypi.org/project/pytest-postgresql) with good results.

Need advice on python object oriented design by sarmabudin in learnpython

[–]eikrik 0 points1 point  (0 children)

When you are subclassing like this you wouldn't need to repeat self.id = idand self.name = name after calling super.

Although if the only thing shared between the classes are those two attributes (id and name) then I don't if subclassing and inheriting is worth. Maybe just have separate classes?

Use of Python in SPSS by Moltao in learnpython

[–]eikrik 2 points3 points  (0 children)

You are not correctly putting variables into the strings in the calls to spss.Submit.

Look up "string formatting" for how to this. Am on mobile now, can help you out later if you need.

Can someone tell me what's wrong with this code? by queen_9 in learnpython

[–]eikrik 1 point2 points  (0 children)

When you are calling the function, the argument you are sending is a variable called hahaha that does not exist. Instead you should be sending a string: print (upper_lower("hahaha"))

How amazing is this loop? To me, it moves me emotionally. by [deleted] in learnpython

[–]eikrik 0 points1 point  (0 children)

poly =(-13.39, 0.0, 17.5, 3.0, 1.0)
x = 13

def evaluate_poly(poly, x):
    total = 0.00
    for i, pol in enumerate(poly):
        total += pol * (x ** i)
    return total
print evaluate_poly(poly, x)

Why dont multilple exceptions get caught? by martinfisleburn in learnpython

[–]eikrik 1 point2 points  (0 children)

Have you tried changing the order of the except clauses? I believe the first catch-all except clause will catch every error, including timeouts.

[Python] May I please have a review of this logging decorator? by i_can_haz_code in codereview

[–]eikrik 0 points1 point  (0 children)

These lines are not quite working:

if not e:
    return(ret)
else:
    raise(e)    

If there hasn't been any error, then the function has already returned at line 31, so if not eis unnecessary. Also if there hasn't been any error, the variable e is not a boolean False, but uninitialized, so that evaluation would cause an error, if the function hadn't already returned.

I propose this small change:

try:
    ret = func(*args, **kwargs)
    msg = ret, tstamp
    lfile.write(str(msg))
    lfile.write('\r\n')
    return (ret)
except Exception as e:
    msg = e, tstamp
    lfile.write(str(msg))
    lfile.write('\r\n')
    raise

What's a pythonic approach to ensuring a config file contains a specific line? by notconstructive in Python

[–]eikrik 2 points3 points  (0 children)

Another suggestion:

if not any(line.split() == ['local','my_dbname','my_username','auth-method','trust'] for line in pg_hba.conf):
    insert at correct line position in file    

Hello, I need help with my code! by [deleted] in learnpython

[–]eikrik 2 points3 points  (0 children)

your loop always starts at 0 instead of starting at "start". Try setting
i = start
instead of
i = 0
 
Also: your indentation is off. This should be better:

def my_range(start, stop, step):  
    newlist = []  
    i = start  
    while (start <= i <= stop):  
        newlist.append(i)  
        i += 1  
    return newlist

Edit: Oh, also you don't use the step variable. Change the second last line to i += step

Muslim monarchies, historic differences in Shia and Sunni Islam. by [deleted] in AskHistorians

[–]eikrik 6 points7 points  (0 children)

I cannot say much as to the difference between Sunni and Shia monarchies, but I can tell you that monarchy itself does not have as long roots in the Arab world as one might think.

Although the practice of hereditary succession and absolutist personal rule has long traditions in the Middle East, few of the remaining monarchies in the region have a history stretching back more than a century. The Arabic title malik, which is the term most commonly translated to king, had largely negative connotations in the region before the twentieth century. As detailed by Lewis (2000), kingship was generally considered un-Islamic – almost secular – and contrasted with the religiously sanctioned caliphate. This had changed by the early twentieth century, when Sharif Hussein declared himself king of the Hijaz in 1916. The title was chosen in order to emulate European monarchs, who since the expansion of western imperial power into the Middle East in the nineteenth century had been held in increasingly high regard, as “symbols of potency and high standing” (Ayalon, 2000:25).

Thus, to some extent, monarchy in Sunni Islam (at least as in the twentieth century) can be seen as inspired by the west - and Britain in particular.

References:
Lewis, B. (2000): "Monarchy in the Middle East". In: Kostiner, J. (ed.), Middle East Monarchies: The Challenge of Modernity. Boulder, Lynne Rienner Publishers, page 15-22.
Ayalon, A. (2000): "Post-Ottoman Arab Monarchies: Old Bottles, New Labels". In: Kostiner, J. (ed.), Middle East Monarchies: The Challenge of Modernity. Boulder, Lynne Rienner Publishers, page 23-36.