How do I change the formatting for my return values in this function?
If your function is return a table then you should treat it like a table. How do we normally look at tables in SQL? We SELECT ... FROM them. You're looking for something more like this:
select ...
from nrt_summary_by_param_id(5);
PHP return value formatting
in your function you concating two strings in first condition, in second condition returned an empty string and in else statement returned that self price without change. so as your return type is string there is no problem for merging your prices with another strings such as html tags. if this process don't make problem for another processes of your wordpress, you can use html tags by concating them in your returns:
function sr_change_variable_price($price, $product){
$html_tag = '<span style={some styles}>%s</span>';
if($product->is_type('variable') AND !is_product()){
$min = $product->get_variation_regular_price('min') . ' ' . $product->get_variation_sale_price('min');
$min = $min ' Ft';
return(sprintf($html_tag, $min));
}elseif($product->is_type('variable') AND is_product()){
return('');
}else{
return(sprintf($html_tag, $price));
}
}
add_filter('woocommerce_get_price_html', 'sr_change_variable_price', 10, 2);
string.Format Return value of pure method is not used
You need to render the value in a code block like this:
@if (Model != null && Model.Order != null)
{
foreach (var item in Model.Order.Where(x => x.OrderInStep2 != null))
{
<text>@String.Format("{0:C}", item.OrderInStep2)</text>
}
}
Return a multiple value dictionary within a function into a pretty format
Dictionaries (like all built-in containers) are represented with their contents shown as representations, essentially using the repr()
function on each. For strings, those are meant to be as helpful as possible in that they are shown as string literals that can simply be copied and pasted to recreate their value. That means they also show unprintable characters or characters with special meaning as escape sequences. Your newline characters are just such characters.
In other words, you can't do what you want just by inserting \n
characters in the string values.
Instead, you need to do your own formatting if you really want to show your dictionary that way. Just print out the keys and values yourself:
def represent_dict(d):
print('{', end='') # no newline
first = True
for key, value in d.items():
# newline at the start, not end, with commas
print('{}\n{!r}: {!r}'.format('' if first else ',', key, value), end='')
first = False
print('}') # closing with a brace and a newline
Remove the \n
addition in your reading code; it can be simplified to just produce the dictionary directly with a dictionary comprehension:
def read_dictionary():
with open("text.tsv") as tsvfile:
tsvreader = csv.reader(tsvfile, delimiter = "\t")
return {row[0]: row[1:] for row in tsvreader}
represent_dict(read_dictionary())
You generally should keep presentation and data structure separate. Those newlines in the keys can easily cause issues elsewhere, and they are only there for the presentation output.
Demo of the output:
>>> dictionary = {"string1":["a","b","c"], "string2":["d","e","f"],
... "string3":["g","h","i"], "string4":["j","k","l"]}
>>> represent_dict(dictionary)
{
'string1': ['a', 'b', 'c'],
'string2': ['d', 'e', 'f'],
'string3': ['g', 'h', 'i'],
'string4': ['j', 'k', 'l']}
Return value of a function in Erlang
In Erlang the last expression in your function is returned, in your case that would be the result of io:format
which is ok
.
To return Cmd
you can simply make it the last expression in your function:
function_test() ->
Cmd = os:cmd("ls"),
io:format("The result of ls is:~p~n", [Cmd]),
Cmd.
Date Function in Insert gives an error. How can I format my date to return the insert values?
This line is the problem:
(18316,'p2','NULL','01-juni-2019'),
-----------------------^^^^ what month is "juni"?
This works:
(18316,'p2','NULL','01-jun-2019'),
But really, you should be using unambiguous formats that don't contain language-specific words, like 20190601
. Otherwise this can still fail, e.g.
SET LANGUAGE German;
INSERT ... VALUES (18316,'p2','NULL','01-jun-2019')
Msg 241 Level 16 State 1
Fehler beim Konvertieren einer Zeichenfolge in ein Datum und/oder eine Uhrzeit.
See Dating Responsibly.
Related Topics
How to Pivot Rows to Columns in MySQL Without Using Case
How to "Reset" Running Sum After It Reaches a Threshold
Login Failed. the Login Is from an Untrusted Domain and Cannot Be Used with Windows Authentication
Find Min and Max for Subsets of Consecutive Rows - Gaps and Islands
How to Select First N Rows from a Table in T-Sql
SQL Server Audit Logout Creates Huge Number of Reads
SQL How to Have a "Conditionally Unique" Constraint on a Table
How to Get the Date and Time from Timestamp in Postgresql Select Query
Is It Better to Do an Equi Join in the from Clause or Where Clause
How to Find All Open/Active Connections in Db2 (8.X)
Problem with MySQL Insert Max()+1
T-Sql: How to Join @Variable Tables (Another Try)
Postgresql Reusing Computation Result in Select Query
SQL Count of Open Orders Each Day Between Two Dates
How to Add Sequenced Number Based on Sorted Value in Query in Access