Syntax: use "^" instead of "**" AND syntax: "^" is not a unary operator

Hi

I am translating Python into Julia.

When converting this python line into Julia I get an error.

oneshotsearch_results = service.jobs.oneshot(searchquery_oneshot, **kwargs_oneshot)
syntax: use "^" instead of "**"

So I modified it into this:

oneshotsearch_results = service.jobs.oneshot(searchquery_oneshot, ^^kwargs_oneshot)

Now the error is:

My whole code is:

results=pyimport("splunklib.results")

kwargs_oneshot = (earliest_time= "2019-09-07T12:00:00.000-07:00",
                  latest_time= "2019-09-09T12:00:00.000-07:00",
                  count=0)

searchquery_oneshot = "search index=iis | stats count by c_ip | head 5" 

oneshotsearch_results = service.jobs.oneshot(searchquery_oneshot, **kwargs_oneshot)

# Get the results and display them using the ResultsReader
reader = results.ResultsReader(oneshotsearch_results)
for item in reader
    println(item)
end

Any insights?

Use ... for splatting

It still does not work.

Hmm, actually probably needs a semicolon: oneshot(searchquery_oneshot; kwargs_oneshot...). That way Julia knows they are keyword arguments, not positional ones

Ok. I got a result this time.
Is there like a “dictionary” or Cheatsheet to translate from Julia to Python or viceversa?

Anyways…
These are my results in Python and in Julia.
I want to put that into a dataframe (ex pandas). And visualize it in a map. As I have ipaddresses and latitude and longitude.

Do you have any suggestions?

IN PYTHON
image

IN JULIA
image

I know of https://cheatsheets.quantecon.org/, but it doesn’t cover splatting. Noteworthy Differences from other Languages · The Julia Language is also helpful, as is the manual as a whole.

The dataframes package in Julia is DataFrames.jl. I know there have been other threads on discourse about mapping visualizations so you might have some luck searching. Best of luck!

3 Likes

Yeah, it’s a little unfortunate that the error message leads you astray in the situation (It’s assuming you’re trying to use ** for exponentiation, which is ^ in Julia).

5 Likes

I’ve just made PR 34706 improve error message for using ** by oscardssmith · Pull Request #34706 · JuliaLang/julia · GitHub with an improvement to the error message.

4 Likes

Pr merged. It should end up in 1.5

1 Like